Vim Cheatsheet

Essential commands for everyday editing

Modes

iInsert before cursor
IInsert at line start
aAppend after cursor
AAppend at line end
oOpen new line below
OOpen new line above
vVisual (character)
VVisual (line)
Ctrl-vVisual (block)
EscReturn to Normal

Navigation

h j k l← ↓ ↑ →
w / bNext / prev word
W / BNext / prev WORD
e / geEnd of next / prev word
0 / ^Line start / first non-blank
$Line end
gg / GFile start / end
{ / }Prev / next paragraph
Ctrl-d / Ctrl-uScroll half page
%Jump to matching bracket

Editing

xDelete char under cursor
ddDelete line
DDelete to end of line
ccChange (replace) line
CChange to end of line
yyYank (copy) line
p / PPaste after / before
u / Ctrl-rUndo / redo
.`Repeat last change
~Toggle case

Operators + Motions

dwDelete word
cwChange word
ywYank word
diwDelete inner word
ci"Change inside quotes
da(Delete around parens
yipYank inner paragraph
guwLowercase word
gUwUppercase word
>> / <<Indent / dedent line

Search & Replace

/patternSearch forward
?patternSearch backward
n / NNext / prev match
* / #Search word under cursor →/←
:%s/old/new/gReplace all in file
:%s/old/new/gcReplace with confirmation
:s/old/new/Replace on current line
:nohClear search highlight

Files & Buffers

:wSave file
:qQuit
:wq / ZZSave and quit
:q!Quit without saving
:e fileOpen file
:bn / :bpNext / prev buffer
:lsList buffers
:bdDelete (close) buffer

Windows & Splits

Ctrl-w sHorizontal split
Ctrl-w vVertical split
Ctrl-w wCycle windows
Ctrl-w h/j/k/lMove between windows
Ctrl-w =Equalize window sizes
Ctrl-w qClose window
:tabnewOpen new tab
gt / gTNext / prev tab

Marks & Jumps

maSet mark a
`aJump to mark a
''Jump to last position
Ctrl-o / Ctrl-iOlder / newer jump
:nGo to line n
H / M / LTop / middle / bottom of screen

Macros & Registers

qaRecord macro into register a
qStop recording
@aPlay macro a
@@Repeat last macro
"ayyYank line into register a
"apPaste from register a
:regShow all registers

Useful Tricks

Ctrl-a / Ctrl-xIncrement / decrement number
JJoin line with next
gdGo to local definition
KKeyword lookup (man page)
:sortSort selected lines
:!cmdRun shell command
gg=GAuto-indent entire file
Ctrl-nAutocomplete (insert mode)