Vim Navigation
100%

Advanced Text-Fu · Lesson 5

Vim Navigation

Learn how to move by characters, words, lines, and file positions in Vim's Normal mode.

Vim provides keyboard motions that work in a terminal without requiring a mouse. Some Vim configurations also support mouse input, but learning motions makes navigation composable with editing commands.

Press Esc before practicing to return to Normal mode.

Moving by Characters and Screen Lines

The foundational Normal-mode motions are:

  • h: Move one character left.
  • j: Move one screen line down.
  • k: Move one screen line up.
  • l: Move one character right.

Arrow keys commonly perform similar movement, but h, j, k, and l keep your hands near other commands. On a wrapped display line, j and k normally move by file lines; gj and gk move by displayed screen lines.

In Normal mode, which key moves the cursor down one line?

Prefixing Motions with Counts

Type a positive count before many motions to repeat them. For example:

5j
3l

5j moves down five lines, while 3l moves right three character positions when possible. Counts also combine with word and editing commands.

What does 4k do in Normal mode?

Moving by Words

Useful word motions include:

  • w: Move to the beginning of the next word.
  • b: Move to the beginning of the current or previous word.
  • e: Move to the end of the current or next word.

Uppercase W, B, and E use whitespace-delimited WORDS, treating punctuation differently. Prefix a count to move through several words, such as 3w.

Which Normal-mode command moves forward to the beginning of the third following word position?

Moving within a Line

These motions target positions on the current line:

  • 0: Move to column zero.
  • ^: Move to the first nonblank character.
  • $: Move to the end of the line.

The difference between 0 and ^ matters on indented lines.

Which motion moves to the first nonblank character of an indented line?

Moving through the File

Use these Normal-mode commands for larger jumps:

  • gg: Move to the first line.
  • G: Move to the final line.
  • 42G: Move to line 42.
  • Ctrl+F: Move forward approximately one screen.
  • Ctrl+B: Move backward approximately one screen.

The command :42 followed by Enter is another way to jump to line 42.

Which Normal-mode command moves to the final line of the buffer?

To practice keyboard navigation while editing a disposable file, try this hands-on lab:

  1. Edit Text Files in Linux with Vim and Nano - Practice creating files, editing text, saving files, and navigating with both Vim and Nano in a real Linux environment.

Lesson complete

You finished Vim Navigation

You can now navigate a Vim buffer at several useful scales.

  • Move by characters or lines with h, j, k, and l.

  • Repeat motions with a numeric prefix.

  • Move between word boundaries with w, b, and e.

  • Target the start, first text, or end of a line.

  • Jump to file positions with gg, G, or a line number.

Keep your learning progress

Create a free account to save this lesson and continue learning on any device.

Create a free account
Next Lesson
Back to Advanced Text-Fu