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
42Gor42ggin normal mode for the same result :$jumps to the last line of the file:0jumps to the very beginning (before line 1)