How to move with motions and counts in Vim

w$G3w

A motion moves the cursor: w to the next word, e to the end of a word, b back a word, 0 and $ to the start and end of the line, gg and G to the first and last line.

Put a number before a motion to repeat it: 3w moves three words. Put an operator before it to act on the text it covers: d2w deletes two words.

Worked example

Delete the first two words.

d2w
Your textVim mode: Normal
Delete the first two words. Before: pack small light bags. After: light bags.

2dw does the same. Count the words before you choose a number; when you are not sure, a text object or a search is safer.

Commands

hjkl
Left, down, up, right.
w
Next word start.
e
End of the word.
b
Back to a word start.
WEB
The same, but a WORD runs from space to space.
0
Start of the line.
^
First character that is not a space.
$
End of the line.
ggG
First line, last line.
3G
Line 3.
%
The matching bracket.
}{
Next or previous blank line between paragraphs.

Jump back

Big jumps, such as G or a search, are remembered. Ctrl-o goes back to where you were and Ctrl-i goes forward again. To mark a place yourself, press m and a letter; ` and the same letter brings you back to it.

Ctrl-o
Back to the place before the jump.
ma`a
Set mark a, then return to it.

Counts set the amount

A count works with edits as well as motions. 3x deletes three characters and 2dd two lines. On a number, Ctrl-a adds one and Ctrl-x subtracts one; with a count, 5 Ctrl-a adds five.

3x
Delete three characters.
Ctrl-a
Add one to the number at or after the cursor.
3Ctrl-a
Add three.
Ctrl-x
Subtract one.

Exceptions

  • A count before G names a line. 3G goes to line 3, not three lines down.
  • w stops at punctuation. W only stops after a space.
  • dw deletes the space after a word; de keeps it.
  • f and t never leave the current line. To reach another line by its text, search with /.

Try it