Vim Cheat Sheet

A reference for the Vim editor, modes, moving around, editing, search and replace, and saving or quitting, including the escape hatch for when you are stuck.

Vim is modal: keys do different things depending on the mode. Press Esc to return to Normal mode, where these commands work. The golden rule if you are stuck: press Esc, then type :q! and Enter to quit without saving.

Modes

KeyEnters
EscNormal mode (navigate, run commands)
i / aInsert before / after the cursor
o / OOpen a new line below / above
v / VVisual (character / line) selection
Ctrl+vVisual block selection
:Command-line mode

Moving around

KeyMoves to
h j k lLeft, down, up, right
w / bNext / previous word
0 / $Start / end of line
gg / GFirst / last line of the file
:NGo to line number N
Ctrl+d / Ctrl+uHalf page down / up

Editing

KeyAction
xDelete the character under the cursor
dd / yyDelete (cut) / yank (copy) the line
dw / cwDelete to start of next word / change to end of word
p / PPaste after / before the cursor
uUndo (Ctrl+r to redo)
.Repeat the last change
N + commandRepeat N times (e.g. 3dd deletes 3 lines)

Search & replace

CommandAction
/textSearch forward (?text backward)
n / NRepeat the search in the same / opposite direction
:%s/old/new/gReplace all occurrences in the file
:%s/old/new/gcReplace all, confirming each one

Saving & quitting

CommandAction
:wSave (write) the file
:wq or ZZSave and quit
:qQuit (fails if there are unsaved changes)
:q!Quit and discard unsaved changes (:qa! for every window)
:wqaSave and quit all open windows

Vim's power is in combining a count, an operator, and a motion, for example d (delete) + 2 + w deletes two words. Run vimtutor in a terminal for a hands-on 30-minute lesson.

What this does

A Vim cheat sheet covers modes, moving around, editing, search and replace, and saving or quitting — including how to exit when you are stuck.

How to use it

  1. Browse by task.
  2. Find the keystrokes you need.
  3. Tap a : or / command to copy it (keystrokes are shown as keys).
  4. Practice in your own file.

Example

Press Esc, then :wq to save and quit.

Last updated .

Frequently asked questions

How do I exit Vim?

Press Esc, then type :q! and Enter to quit without saving, or :wq to save and quit. ZZ also saves and quits.

Why does typing not insert text?

Vim starts in Normal mode, where keys run commands. Press i to enter Insert mode and type, then press Esc to return to Normal mode.

How can I learn Vim properly?

Run vimtutor in a terminal, it is a built-in, hands-on lesson that takes about 30 minutes and covers the fundamentals.