Vim Cheatsheet
Motions and Marks
Use this Vim reference while you build software engineering projects, review code, or refresh the syntax you reach for most.
Character and Line Motions
| Key | Moves to |
|---|---|
h j k l | left, down, up, right |
0 | First column of the line |
^ | First non-blank character |
$ | End of line |
g_ | Last non-blank character |
gg | First line of the file |
G | Last line of the file |
42G or :42 | Line 42 |
gj gk | Down/up by screen line (wrapped text) |
g0 g$ | Start/end of the screen line |
+ - | First non-blank of next / previous line |
| | Column 1; 20| goes to column 20 |
Word Motions
| Key | Moves to |
|---|---|
w | Start of next word |
W | Start of next WORD (whitespace-delimited) |
b | Start of previous word |
B | Start of previous WORD |
e | End of current or next word |
E | End of current or next WORD |
ge | End of previous word |
A word stops at punctuation, a WORD only at whitespace. In foo.bar_baz, w walks foo → . → bar_baz, while W jumps over the whole thing.
Find on the Line
| Key | Action |
|---|---|
f{char} | Jump forward onto the next {char} |
F{char} | Jump backward onto the previous {char} |
t{char} | Jump forward until just before {char} |
T{char} | Jump backward until just after {char} |
; | Repeat the last f/t in the same direction |
, | Repeat it in the opposite direction |
" Cursor at the start of: parse(input, opts) f, " lands on the comma dt) " deletes ' opts' up to but not including ')' ci( " change everything inside the parentheses
Screen and Scrolling
| Key | Action |
|---|---|
H M L | Top / middle / bottom line of the screen |
zt zz zb | Scroll so the current line is at top / center / bottom |
Ctrl-e Ctrl-y | Scroll one line down / up |
Ctrl-d Ctrl-u | Scroll half a screen down / up |
Ctrl-f Ctrl-b | Scroll a full screen forward / back |
zz is the one to build a habit around: it recenters what you are reading without moving the cursor.
Paragraphs, Sentences, Brackets
| Key | Moves to |
|---|---|
{ } | Previous / next blank line (paragraph) |
( ) | Previous / next sentence |
% | The matching bracket, paren, or brace |
[[ ]] | Previous / next section (or top-level {) |
[{ ]} | Start / end of the enclosing block |
[( ]) | Start / end of the enclosing parens |
[m ]m | Start of previous / next method (Java-like) |
Jumps and Changes
Vim records a jumplist and a changelist so you can retrace your steps.
| Key | Action |
|---|---|
Ctrl-o | Go to the previous position in the jumplist |
Ctrl-i or Tab | Go to the next position |
:jumps | Show the jumplist |
g; | Go to the previous change |
g, | Go to the next change |
:changes | Show the changelist |
` ` | Back to the position before the last jump |
'' | Back to the line before the last jump |
` . `` | To the position of the last change |
gi | Insert mode at the last insert position |
gv | Reselect the last Visual selection |
A "jump" is a big move (G, /, %, {). Small moves like j and w do not touch the jumplist, which is what makes Ctrl-o useful.
Marks
| Key | Action |
|---|---|
m{a-z} | Set a mark, local to the buffer |
m{A-Z} | Set a global mark (works across files) |
` {mark} `` | Jump to the mark's exact position |
'{mark} | Jump to the mark's line |
:marks | List every mark |
:delmarks a b | Delete marks a and b |
:delmarks! | Delete all lowercase marks |
| Automatic mark | Set to |
|---|---|
` [ ` ] `` | Start / end of the last change or yank |
` < ` > `` | Start / end of the last Visual selection |
` " `` | Position when you last left the file |
` ^ `` | Position where Insert mode was last stopped |
ma " mark this spot as 'a' G " go read the end of the file `a " snap back exactly where you were d'a " or: delete from here to the line of mark a
Counts and Relative Numbers
Motions take counts, and with relative line numbers on you can read the count straight off the gutter.
:set number relativenumber " absolute on the cursor line, relative elsewhere| Command | Action |
|---|---|
5j | Down 5 lines |
d7k | Delete 7 lines upward |
3fx | Jump to the third x on this line |
2} | Forward 2 paragraphs |
10x | Delete 10 characters |