Fork me on GitHub

A Reasonably Okay Vim Cheat Sheet

This is a remix of http://vimsheet.com.

This cheat sheet assumes that you already know how Vim works, conceptually speaking, but want a quick reference for the default key mappings and a way to remind yourself of some of the more clever things that Vim is capable of.

In light of that, this sheet aims to be fairly thorough in its coverage, but also to illustrate patterns in Vim's design that can make commands easier to remember.

Everything here should be compatible with stock Vim, and assumes that the reader is more interested in maintaining compatibility with any given server they SSH into than they are in having a super-tricked-out local development environment. In practice, this means that plugins and .vimrc hacks are suggested to be used only when they would not conflict with the muscle memory one builds up making edits using stock vim.

From the author: I add content and revise sections of the original cheat sheet as I delve into each feature and absorb those parts of the manual. As you might expect, I am making this to be a useful reference for myself first and foremost.

Notation

The notational convention here is to use the same syntax for combination shortcuts as would be used when writing a key mapping or macro. That is, instead of Ctrl+r or CTRL-R, we will write <C-r>. See also :help key-notation.

Normal Mode - Motions

Cursor Movement

Any motion (or command) can be prefixed with a number [count] to iterate it that many times.

The four directions in Vim, keys h, j, k, and l.
Words separated by: punctuation whitespace
Start of next word w W
End of next word e E
Beginning of previous word b B
End of previous word ge gE

Left-right Shortcuts

Seeking Within a Line

Larger Movements

More Advanced

Normal Mode - Editing Text

Be sure to see Registers below for how they work with yanked and deleted text.

Put cursor/line behavior depends on whether the the register contains characterwise or linewise text.

Entering Insert Mode

lowercase uppercase
Insert (i) i - insert in front of cursor I - ... in front of the first non-whitespace in the line
Append (a) a - insert after the cursor A - ... at the end of the line
Open (o) o - insert to a new line below the cursor O - ... above the cursor
Substitute (s) s - remove char at the cursor first S - Clear entire line first (same as cc)

Single-character edits

Multiple-character Edits

Yank (y) Delete (d) Change (c) - Delete and enter insert mode
[noun] y[noun] d[noun] c[noun]
entire line yy or Y dd cc
from cursor to the end of the line y$ D C

A noun can be a motion, like 2W (two whitespace-delimited words) or a text object like it (inner tag block). See also Text Objects.

Indenting

Undo/Repeat

Insert Mode [incomplete]

Visual Mode

Visual commands

Type any of these while some text is selected to apply the action

Registers

Prefix most yank/delete/change commands with "[reg] where [reg] is a specific register to copy to or from.

Text Objects

Objects must be prefixed with a or i, for "a" ("an") object or "inner" object.

In practice, use these objects in context of another command, with the a/i prefix, like cib.

Command Mode

Exiting

Running External Commands

Search/Replace [unrevised]

Working with multiple files - Tabs [unrevised]

Working with multiple files - Buffers [unrevised]

Marks

Marks allow you to jump to designated points in your code.

Vim Help

Other Tips

.vimrc

On macOS, Vim's included .vimrc file turns on a lot of convenient features like mouse support. You might want to make some of the following tweaks. Remember that the <Leader> key, by default, is \.

Reload .vimrc on Save

if has("autocmd")
    autocmd BufWritePost .vimrc source $MYVIMRC
endif

Line Numbering

set number
set relativenumber

Visible Whitespace

set listchars=tab:\|\ ,space:ยท
set list
" Set a shortcut to toggle visible whitespace on and off.
nmap <Leader>l :set list!<CR>
" Must be double-escape to avoid conflicting with mouse scroll
nmap <Esc><Esc>:noh<CR><Esc>

Plugins [incomplete]

vim-plug

Map Caps Lock to Control

No, not Escape. You don't actually need to use escape if you use <C-[> instead. On the machine that Bill Joy originally used to write vi, the control key was placed where caps lock is on most keyboards today. Escape was placed where the tab key is today, so if you want to be totally based, you could try swapping those.

Some people also like mapping jk to exit insert mode. The problem with this is that you would have to accomplish it in your .vimrc, and this would violate our stated intention of not messing with muscle memory when remoting into other machines. The Caps Lock/Tab remaps above can be accomplished on the operating system level, or better yet on the keyboard hardware level, so they don't depend on the particular .vimrc file in the environment you are interacting with.

See Also

References