Vim Cheat Sheet
The daily Vim set: modes, movement, editing, search & replace, visual mode, splits, and key settings.
Modes
Esc # back to Normal mode (the home base)
i # insert before cursor
a # insert after cursor
o # open a new line below, enter insert mode
O # open a new line above, enter insert mode
v # visual mode (select characters)
V # visual line mode (select whole lines)
Ctrl+v # visual block mode (select a rectangle)
Movement
h j k l # left, down, up, right (arrow keys work too)
w # jump to start of next word
b # jump to start of previous word
0 # jump to start of line
^ # jump to first non-blank character of line
$ # jump to end of line
gg # go to first line of file
G # go to last line of file
42G # go to line 42
H / M / L # jump to top / middle / bottom of screen
Ctrl+u # scroll up half a page
Ctrl+d # scroll down half a page
Ctrl+f # scroll forward one full page
Ctrl+b # scroll backward one full page
% # jump to matching bracket () [] {}
Editing
x # delete character under cursor
X # delete character before cursor
dw # delete to start of next word
d$ (or D) # delete from cursor to end of line
dd # delete (cut) current line
cc (or S) # delete line and enter insert mode
C # delete to end of line, enter insert mode
yy # yank (copy) current line
p # paste after cursor (below line for linewise)
P # paste before cursor (above line for linewise)
J # join current line with the one below
u # undo
Ctrl+r # redo
. # repeat last change (the most underrated key)
Search & replace
/pattern # search forward for pattern, Enter to confirm
?pattern # search backward for pattern
n # jump to next match (same direction)
N # jump to previous match (opposite direction)
* # search forward for the word under cursor
# # search backward for the word under cursor
:%s/old/new/g # replace all "old" with "new" in the whole file
:%s/old/new/gc # same, but ask for confirmation on each match
:s/old/new/g # replace on current line only
:noh # clear search highlighting
Visual mode
v # select characters, move with hjkl to extend
V # select whole lines
Ctrl+v # select a rectangular block (great for columns)
y # yank (copy) the selection
d # delete (cut) the selection
c # delete selection and enter insert mode
> # indent selection one level
< # un-indent selection one level
gv # re-select the last visual selection
Splits & tabs
:sp [file] # horizontal split (same file if no name given)
:vsp [file] # vertical split
Ctrl+w w # cycle to the next window
Ctrl+w h/j/k/l # move to the left/down/up/right window
Ctrl+w q # close the current window
:tabnew [file] # open a new tab
gt # go to next tab
gT # go to previous tab
Save & quit
:w # save (write) the file
:q # quit (fails if there are unsaved changes)
:wq # save and quit
:q! # quit, discarding all changes
ZZ # save and quit (normal-mode shortcut)
Settings you'll actually use
:set number # show line numbers
:set relativenumber # relative line numbers (great with 5j / 3k jumps)
:set hlsearch # highlight search matches
:set ignorecase # case-insensitive search
:set tabstop=4 # a tab counts as 4 columns
:set expandtab # insert spaces instead of tab characters
:syntax on # enable syntax highlighting