Vim Cheat Sheet

Modes, motions, edits, search and replace, registers, splits, macros. The 100 commands you actually use.

Modes
Esc
Return to Normal mode (the home base)
i
Insert mode at cursor
a
Insert mode after cursor
I
Insert at start of line
A
Insert at end of line
o
New line below, enter Insert
O
New line above, enter Insert
v
Visual (character) mode
V
Visual Line mode
Ctrl+v
Visual Block mode (column selection)
R
Replace mode (overwrites)
:
Ex command mode (e.g. :w, :q)
Save & Quit
:w
Write (save)
:w <file>
Write to a different file
:q
Quit (fails if unsaved changes)
:q!
Quit, discarding changes
:wq
Write and quit
:x
Write (only if changed) and quit
ZZ
Same as :x (Normal mode shortcut)
ZQ
Same as :q! (Normal mode shortcut)
:wa
Write all open buffers
:qa
Quit all
Cursor Motion
h j k l
Left, down, up, right
w
Forward to next word start
b
Back to previous word start
e
Forward to word end
0
Start of line
^
First non-blank char on line
$
End of line
gg
Top of file
G
Bottom of file
42G
Jump to line 42
:42
Same: jump to line 42
{ }
Previous/next paragraph (blank-line separated)
%
Jump to matching bracket / paren
Ctrl+u
Half page up
Ctrl+d
Half page down
Ctrl+f
Full page down (forward)
Ctrl+b
Full page up (back)
f<c>
Forward to next occurrence of char on line
F<c>
Backward to previous occurrence
t<c>
Forward UNTIL char (stops one before)
;
Repeat last f/F/t/T
Editing
x
Delete char under cursor
X
Delete char before cursor (backspace)
dd
Delete (cut) line
5dd
Delete 5 lines
dw
Delete word
d$
Delete to end of line (same as D)
d0
Delete to start of line
dG
Delete to end of file
cc
Change (delete and enter Insert) line
cw
Change word
C
Change to end of line
r<c>
Replace single char with c
~
Toggle case of current char
yy
Yank (copy) line
yw
Yank word
y$
Yank to end of line
p
Paste after cursor
P
Paste before cursor
u
Undo
Ctrl+r
Redo
.
Repeat last change
J
Join current line with next
>>
Indent line right
<<
Indent line left
==
Auto-indent line
Text Objects (combine with d, c, y, v)
iw
Inner word (diw = delete word)
aw
A word (with surrounding whitespace)
i" or i'
Inside quotes (ci" = change inside quotes)
i( or i)
Inside parentheses
i[ or i]
Inside brackets
i{ or i}
Inside braces
it / at
Inside / around HTML/XML tag
ip / ap
Inside / around paragraph
Pattern to internalize: {operator}{count}{motion}. d2w = delete 2 words. y3j = yank 3 lines down. c$ = change to end of line. Once this clicks, every other Vim trick gets cheap.
Search
/pattern
Search forward
?pattern
Search backward
n
Next match
N
Previous match
*
Search forward for word under cursor
#
Search backward for word under cursor
:noh
Clear search highlights
:set hlsearch
Highlight search results
:set incsearch
Incremental (live) search
Search & Replace
:s/foo/bar/
Replace first match on current line
:s/foo/bar/g
Replace all on current line
:%s/foo/bar/g
Replace all in file
:%s/foo/bar/gc
Replace all with confirmation
:%s/foo/bar/gi
Replace all, case-insensitive
:5,15s/foo/bar/g
Replace on lines 5-15
:'<,'>s/foo/bar/g
Replace in visual selection (auto-filled if selected first)
Splits & Tabs
:split
Horizontal split
:vsplit
Vertical split
Ctrl+w h/j/k/l
Move between split panes
Ctrl+w =
Equal-size all panes
Ctrl+w q
Close current pane
Ctrl+w o
Close all but current pane
:tabnew
New tab
gt
Next tab
gT
Previous tab
Buffers (open files)
:e file
Open file in current window
:ls
List open buffers
:bn
Next buffer
:bp
Previous buffer
:b 3
Switch to buffer 3 (use :ls to see numbers)
:bd
Close current buffer
Registers
"ay
Yank into register a
"ap
Paste from register a
"+y
Yank into system clipboard (if compiled with +clipboard)
"+p
Paste from system clipboard
:reg
Show all register contents
"_d
Delete into the "black hole" (don't pollute paste register)
Marks
ma
Set mark a at cursor
'a
Jump to line of mark a
`a
Jump to exact position of mark a
''
Jump back to position before last jump
`.
Jump to last edit position
:marks
Show all marks
Macros
qa
Start recording macro into register a
q
Stop recording
@a
Replay macro a
@@
Replay last macro
100@a
Replay macro 100 times (handy for batch transforms)
Visual Mode Operations
d
Delete selection
y
Yank selection
c
Change selection
>
Indent right
<
Indent left
u / U
Lowercase / Uppercase selection
~
Toggle case
o
Move to other end of selection
Useful Settings (~/.vimrc)
:set number
Show line numbers
:set relativenumber
Relative line numbers (great with motions)
:set tabstop=4
Tab width
:set expandtab
Use spaces instead of tabs
:set ignorecase
Case-insensitive search
:set smartcase
Case-sensitive when search has uppercase
:set clipboard=unnamedplus
Use system clipboard by default (Linux)
:syntax on
Syntax highlighting