My VIM Cheatsheet

This is my ongoing Vim quick reference. Note that this is in no way meant to be an exhaustive cheatsheet for Vim. This is more a list of things I’m personally constantly forgetting how to do.

Searching, Pattern Matching, and Replacing

Searching for a Pattern

:/pattern

Find and Replace

:%s/searchtext/replacetext/g

Note: Leave off the /g to only replace the first match on each line.

Limit the Range of Affected Lines

:N,Ms/searchtext/replacetext/g

Where N is the first line and M is the last line.

Show All Lines That Match a Pattern

:g/pattern

Delete All Lines that Contains a Pattern

:g/searchpattern/d

Delete All Lines that Do Not Contain a Pattern

:v/searchpattern/d

or

:g!/searchpattern/d

Registers

In Vim, the concept of a clipboard is called a register. Like any other text-editor, Vim has a default register that you can use for copy and paste, but you can also use each letter (a through z) to have multiple named registers.

In Normal Mode

In Edit Mode

Bookmarks

Vim allows you to set bookmarks using the letters a through z so you can more easily refer to a section of a given file.

Inverting Case