Overview

Vim commands compose as operator + motion (or text object), optionally with a count: d3w deletes three words. Terminal multiplexing is in tmux-commands; the regex flavor differs from other tools, see regex-patterns.

Modes and basics

Stay in Normal mode and enter Insert only to type.

KeyEffect
Esc, Ctrl-[Normal mode (press twice when unsure).
i a o I A OInsert before / after / new line below / at line start / at line end / new line above.
v, V, Ctrl-vVisual: characters, lines, block.
:w, :q, :wq, :q!Write, quit, both, quit and discard.
u, Ctrl-r, .Undo, redo, repeat the last change.

Motions

Use counts and f or t motions instead of repeated h and l.

MotionMoves to
h j k lLeft, down, up, right.
w b eNext word start / previous word start / word end (W B E use whitespace-delimited WORDs).
0 ^ $Line start / first non-blank / line end.
gg G :42File start / end / line 42.
{ } %Previous / next blank line, matching bracket.
f{c} t{c}On / just before the next c on the line (F T go backward; ; , repeat).
Ctrl-d Ctrl-uHalf page down / up.

Operators and text objects

Compose an operator with a text object instead of selecting by hand.

OperatorAction
d c yDelete, change (then insert), yank.
> < =Indent, de-indent, auto-indent.
gU guUppercase, lowercase.
dd cc yyWhole-line forms.
Text objectSelects
iw awWord without / with surrounding space.
i" a", i( a(, i{ a{Inside / around quotes, parentheses, braces.
it atInside / around an HTML or XML tag.
ip apParagraph.

ci" changes everything inside double quotes; da( deletes a parenthesized expression with its parentheses.

Search and replace

Add c to confirm replacements across a file.

CommandEffect
/pat, ?pat, n, NSearch forward, backward, next, previous.
*, #Search for the word under the cursor.
:%s/old/new/gReplace in the whole file; add c to confirm each.
:10,20s/old/new/gReplace in a line range.
:'<,'>s/old/new/gReplace in the visual selection.
:nohClear search highlighting.

Start a pattern with \v (“very magic”) to use + ( ) | unescaped; @ is then special, so write a literal one as \@: :%s/\v(\w+)\@(\w+)/\1 at \2/g.

Registers and macros

Record macros that end where the next run can start.

CommandEffect
"ayy, "apYank a line into register a, paste from it.
"+y, "+pYank to, paste from the system clipboard.
"_ddDelete into the black-hole register; yank register untouched.
:regShow registers.
qa … q, @a, @@, 10@aRecord into a, play, replay last, play ten times.

Gotchas

Avoid these; each loses a yank, an edit, or a pattern match.

GotchaFix
x and dd overwrite the unnamed register, losing your last yank.Yank into a named register, or delete with "_.
:q! discards changes without asking.Use :wq, or :wqa to save every buffer.
Without \v, +, (, and | are literals in a pattern.Prefix \v, or escape them.
Pasting from the system clipboard can stair-step indentation.Modern Vim and Neovim handle bracketed paste; otherwise :set paste then :set nopaste.
A macro that ends mid-line replays badly with a count.End it on a motion that sets up the next run.