vimtricks.wiki Concise Vim tricks, one at a time.

How do I jump directly to a specific line number in Vim?

Answer

:<line-number>

Explanation

When you know the exact line number you want to navigate to, the colon command is the quickest way to get there. This is especially useful when debugging errors that reference specific line numbers.

How it works

  • : enters command-line mode
  • Type the line number (e.g., :42) and press Enter
  • The cursor moves to the beginning of that line

Example

Starting at line 1 of a file:

line 1
line 2
line 3
...
line 42

After typing :42<CR>, the cursor lands on line 42.

Tips

  • You can also use 42G or 42gg in normal mode for the same result
  • :$ jumps to the last line of the file
  • :0 jumps to the very beginning (before line 1)

Next

How do you yank a single word into a named register?