$ command-helper

Vim

Surviving and being productive: modes, moving, editing, search and replace, buffers and splits.

Requires Google sign-in

Essentials

Save and quit
:wq
Quit without saving
:q!
Save a file you opened without sudoadvanced
:w !sudo tee % > /dev/null
Back to normal mode
Esc
Insert before cursor / at line end / new line below
i  /  A  /  o
Undo / redo
u  /  Ctrl+r

Moving

Start / end of file
gg  /  G
Go to line 42
:42
Next / previous word
w  /  b
Start / end of line
0  /  $
Jump to matching bracket
%

Editing

Delete / copy / paste a line
dd  /  yy  /  p
Change the word under the cursor
ciw
Change 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  →  …  →  Esc

Select 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  w
Turn on line numbers and syntax highlighting
:set number | syntax on
Paste without auto-indent breaking itadvanced
:set paste