Skip to content

Vim cheat sheet

Vim works as verb + count + motion: d2w deletes two words, ci" changes inside quotes. Learn the pieces and they combine.

28 entries

Survival

i  a  o

Insert before cursor, after cursor, on a new line below.

Esc

Back to normal mode.

:w  :q  :wq  :q!

Save, quit, save and quit, quit without saving.

u  Ctrl-r

Undo, redo.

Motions

h j k l

Left, down, up, right.

w  b  e

Next word, back a word, end of word.

0  ^  $

Line start, first non-blank, line end.

gg  G  42G

First line, last line, line 42.

%

Jump to matching bracket.

f x  t x  ;

To / till character x on the line; repeat.

Editing

x  dd  D

Delete char, line, to end of line.

yy  p  P

Yank (copy) line, paste after, paste before.

cw  cc  C

Change word, line, to end of line.

>>  <<  =

Indent, outdent, auto-indent.

.

Repeat the last change.

J

Join the line below.

Text objects

ciw  diw

Change / delete inner word.

ci"  da(

Change inside quotes; delete around parentheses.

cit  vip

Change inside an HTML tag; select paragraph.

Search & replace

/pattern  n  N

Search forward; next; previous.

*  #

Search word under cursor forward / back.

:%s/old/new/g

Replace everywhere in the file.

:%s/old/new/gc

Replace with confirmation.

Visual mode

v  V  Ctrl-v

Character, line, block selection.

Ctrl-v jj I// Esc

Block insert: comment several lines.

Files, windows, macros

:e file  :ls  :b2

Open file, list buffers, switch buffer.

:sp  :vs  Ctrl-w w

Horizontal / vertical split, cycle windows.

qa … q  @a  @@

Record macro in register a, play it, repeat.

Frequently asked questions

How do I exit Vim?

Press Esc, then type :q and Enter. Use :wq to save first or :q! to discard changes.

What is the difference between yank and delete?

Both put text in a register, so you can paste either with p. Yank leaves the text in place; delete removes it.

How do I replace text in the whole file?

Use :%s/old/new/g. Add c at the end to confirm each replacement.

Related cheat sheets