Moving Around

Vim expects you to keep your hands on the home row, so the arrow keys are a crutch you’re about to drop. Everything in this chapter happens in Normal mode.

The basic four

h j k l move left, down, up, and right. That’s the whole set. Yes, j looks like it should mean “jump” and it doesn’t; the mnemonic that sticks for most people is that j has a little hook at the bottom, pointing down.

It feels slower than arrow keys for the first day. By the third day, not having to move your hand off the home row starts to feel faster, because it is.

Moving by word

w jumps to the start of the next word. b jumps back to the start of the previous word. e jumps to the end of the current or next word. Capitalized versions (W, B, E) do the same thing but treat punctuation as part of the word, useful when you’re moving through code with lots of symbols.

Moving by line

0 jumps to the very start of the line. ^ jumps to the first non-blank character on the line (useful when a line starts with indentation). $ jumps to the end of the line.

Moving by bigger chunks

gg jumps to the top of the file. G jumps to the bottom. Typing a number before G, like 12G, jumps to line 12. { and } jump up and down by paragraph (a paragraph, to Vim, is a block of text separated by blank lines).

Counts: the multiplier trick

Almost any motion can be prefixed with a number to repeat it. 3j moves down three lines. 5w moves forward five words. This is one of the things that makes Vim fast once it’s automatic: you look at where you want to go, count roughly how far it is, and jump there in one move instead of tapping a key repeatedly.

Try it

Open a file with several paragraphs of text (any markdown file works, including this one, opened in a second terminal) and practice:

  1. Use hjkl exclusively for two minutes. Resist the urge to reach for arrow keys, even when it feels slower.
  2. Jump to the last line with G, then back to the first with gg.
  3. Place your cursor in the middle of a word and practice w, b, and e until you can predict where each one lands before you press it.
  4. Use 0 and $ to jump to the start and end of a line with mixed content.
  5. Try 4j to jump down four lines in one move, then 6w to jump forward six words.

← Modes