Vim Commands

Vim commands cheatsheet.

Modes, motion, editing and search — the Vim commands that get you productive fast. Tap to copy.

Modes & saving
iEnter insert mode before the cursor
aEnter insert mode after the cursor
EscReturn to normal mode
:wSave the file
:qQuit
:wqSave and quit
:q!Quit without saving
Moving
h j k lMove left, down, up, right
wJump to the start of the next word
bJump back to the previous word
0Go to the start of the line
$Go to the end of the line
ggGo to the first line
GGo to the last line
:42Jump to line 42
Editing
xDelete the character under the cursor
ddDelete the current line
yyCopy (yank) the current line
pPaste after the cursor
uUndo
Ctrl + rRedo
dwDelete to the end of the word
ccChange (replace) the whole line
Search & replace
/textSearch forward for text
nJump to the next search match
NJump to the previous match
:%s/old/new/gReplace every occurrence in the file
:%s/old/new/gcReplace with confirmation for each
Commands are typed in normal mode (press Esc first). Type :wq then Enter to save and quit if you're stuck.

Stop fighting Vim

The mental model: normal mode for moving and commands, insert mode (press i) for typing, and Esc to get back. Master a few motions (w, b, 0, $, gg, G) and edits (dd, yy, p, u) and the rest follows. To save and quit, type :wq.

FAQ

How do I exit Vim?
Press Esc to make sure you're in normal mode, then type :wq and Enter to save and quit, or :q! and Enter to quit without saving.
How do I find and replace in Vim?
Use :%s/old/new/g to replace every occurrence in the file, or add c (:%s/old/new/gc) to confirm each change.

More cheatsheets