The one editor guaranteed to be on every server you SSH into. You don't need to know all of Vim — you need enough to edit a config file and get out safely.
Modes
iEnters insert mode before the cursor.
EscReturns to normal mode from insert, visual, or command mode.
vEnters visual mode, for selecting text character by character.
:Enters command mode, for ex commands like :w, :q, :s.
Saving & Quitting
:wWrites (saves) the file.
:qQuits — fails if there are unsaved changes.
:wqWrites then quits.
:q!Quits and discards unsaved changes. There is no undo once you've quit — confirm you actually want to lose the edits first.
ZZShorthand for :wq in normal mode.
Navigation
h j k lLeft, down, up, right — the original arrow keys, still faster than reaching for real ones.
wJumps to the start of the next word.
bJumps to the start of the previous word.
0Jumps to the start of the current line.
$Jumps to the end of the current line.
ggJumps to the first line of the file.
GJumps to the last line of the file.
:42Jumps to line 42.
Editing
ddDeletes (cuts) the current line.
yyYanks (copies) the current line.
pPastes after the cursor/current line.
uUndoes the last change.
Ctrl-rRedoes a change that was just undone.
xDeletes the character under the cursor.
dwDeletes from the cursor to the start of the next word.
ccDeletes the current line and enters insert mode — change the whole line in one step.
Search & Replace
/patternSearches forward for a pattern. Press n for the next match, N for the previous.
?patternSearches backward for a pattern.
:%s/old/new/gReplaces every occurrence of old with new on every line in the file.
:%s/old/new/gcSame, but prompts for confirmation before each replacement — safer for a change you're not fully sure of.
Visual Mode
vCharacter-wise visual selection.
VLine-wise visual selection.
Ctrl-vBlock-wise visual selection, for editing a rectangular column across multiple lines.
>Indents the selected lines (in visual mode).
Buffers & Files
:e filenameOpens another file in the current window.
:bnextSwitches to the next open buffer.
:lsLists all open buffers.
Ctrl-w sSplits the window horizontally.
Ctrl-w vSplits the window vertically.
Stuck in Vim?
Press Esc a few times to guarantee you're in normal mode, then type :q! and Enter to quit without saving —
the fastest way out if you opened it by accident.