How to move with motions and counts in Vim
w$G3wA motion moves the cursor. w goes 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, so 3w moves three words. Put an operator before it to act on the text it covers, so d2w deletes two words.
Worked example
Delete the first two words.
2dw does the same. Count the words before you choose a number. When you're 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. Then ` and the same letter bring 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, and de keeps it.
- f and t never leave the current line. To reach another line by its text, search with /.