The Vim commands a beginner needs, grouped in the order you learn them. Each group names the Vimrealm chapter that teaches it, so you can practise any command in the game instead of just reading about it.
All of these are typed in Normal mode, the mode Vim starts in, unless the table says otherwise. Press Esc to get back to Normal mode from anywhere. A {c} means "any character" and {n} means "a number".
How to save and quit Vim
Type these in Normal mode. Each one starts a command line at the bottom of the screen and runs when you press Enter.
Keys
What it does
:w
save the file
:q
quit (Vim refuses if there are unsaved changes)
:wq
save and quit
:q!
quit and throw away unsaved changes
ZZZQ
the Normal mode shortcuts for :x (save if changed, then quit) and :q!
:e!
reload the file and throw away unsaved changes
Basic movement: h j k l
Your fingers stay on the home row. Put a number in front of almost any command to repeat it.
Keys
What it does
hl
move left / right one character
jk
move down / up one line. The cursor remembers its column when it passes shorter lines.
{n}
prefix a number to repeat: 5j, 3w, 2dd
Practise in chapter 1, Meadow of Motion (free).
Moving by word
A word is a run of letters, digits and underscores, or a run of punctuation. A WORD is anything separated by spaces, so foo.bar(x) is several words but one WORD.
Keys
What it does
w
jump to the start of the next word
b
jump back to the start of a word
e
jump to the end of the word
ge
jump back to the end of the previous word
WBEgE
the same four moves by WORD
Practise in chapter 2, Forest of Words (free).
Start and end of a line
Keys
What it does
0
jump to column zero
^
jump to the first non-blank character
$
jump to the end of the line
g_
jump to the last non-blank character, skipping trailing spaces
Practise in chapter 3, Cliffs of Line's End (free).
Find a character in the line: f, t, ; and ,
Keys
What it does
f{c}
jump onto the next {c} in the line
F{c}
jump onto the previous {c} in the line
t{c}
jump till just before the next {c}
T{c}
jump till just after the previous {c}
;
repeat the last f, t, F or T
,
repeat it in the opposite direction
Practise in chapter 4, Seeker's Cave (free).
Moving through the whole file
Keys
What it does
gg
go to the first line
G
go to the last line
{n}G or :{n}Enter
go to line {n}
}{
jump to the next / previous blank line (paragraph)
%
jump to the matching bracket
Practise in chapter 5, Mountain of Lines (free).
Small edits, undo and redo
Keys
What it does
x
delete the character under the cursor
X
delete the character before the cursor
r{c}
replace the character under the cursor with {c}
dd
delete the whole line
~
toggle the case of the character under the cursor: 5~ toggles five
J
join the line below onto this one, with one space between
gJ
join the line below as it is, adding and removing no spaces
u
undo the last change
Ctrl-r
redo an undone change
Practise in chapter 6, The Breaking Arts (full version).
Insert mode
Each of these switches to Insert mode, where keys type text. Press Esc to return to Normal mode.
Keys
Starts typing…
i
before the cursor
a
after the cursor
I
at the first non-blank character of the line
A
at the end of the line
o
on a new line below
O
on a new line above
R
in Replace mode: each character types over the one under the cursor, and Backspace brings the old one back
Practise in chapter 7, Scribe's Tower (full version).
Operators: verb + motion
This is where Vim gets its power. An operator is a verb, and any motion from above says how far it reaches: dw deletes to the next word, d$ to the end of the line, dt) up to the next ). Typing the operator twice works on the whole line.
Keys
What it does
d{motion}
delete over a motion: dw, d$, dt)
c{motion}
delete over a motion, then start Insert mode: cw, c$
D
delete to the end of the line (same as d$)
C
change to the end of the line (same as c$)
cc or S
change the whole line
s
delete the character and start Insert mode (same as cl)
gu{motion}gU{motion}
lowercase / UPPERCASE over a motion: gUiw, gu$. guu and gUU work on the line
g~{motion}
toggle case over a motion; g~~ toggles the line
Practise in chapter 8, Operator Sanctum (full version).
Text objects
After an operator, a text object picks a whole thing around the cursor, wherever the cursor is inside it. i means "inner" (just the contents) and a means "a" (the contents plus the quotes, brackets or surrounding space). So ciw changes the word under the cursor and di( empties a pair of parentheses.
Keys
Selects
iwaw
the word under the cursor / plus surrounding space
iWaW
the WORD under the cursor / plus surrounding space