Vim
Surviving and being productive: modes, moving, editing, search and replace, buffers and splits.
Essentials
Save and quit
:wqQuit without saving
:q!Save a file you opened without sudoadvanced
:w !sudo tee % > /dev/nullBack to normal mode
EscInsert before cursor / at line end / new line below
i / A / oUndo / redo
u / Ctrl+rMoving
Start / end of file
gg / GGo to line 42
:42Next / previous word
w / bStart / end of line
0 / $Jump to matching bracket
%Editing
Delete / copy / paste a line
dd / yy / pChange the word under the cursor
ciwChange text inside quotes or brackets
ci" / ci(Visual line selection, then indent
V then >Repeat the last change
.Insert the same text on many lines (block mode)advanced
Ctrl+v → j / k → I → … → EscSelect lines down/up with j/k, press I, type the text, then Esc — it appears on every selected line.
Search and replace
Search forward, next / previous match
/<pattern> then n / N
Replace in the whole file
:%s/<old>/<new>/g
Replace with confirmation
:%s/<old>/<new>/gc
Delete all lines matching a patternadvanced
:g/<pattern>/d
Files and windows
Split horizontally / vertically
:sp <file> / :vsp <file>
Move between splits
Ctrl+w wTurn on line numbers and syntax highlighting
:set number | syntax onPaste without auto-indent breaking itadvanced
:set paste