Vim Scoops / Lessons / Go to a line

How to go to a line number in Vim

Type :42 and press Enter to jump to line 42. 42G does the same. gg goes to the first line and G to the last.

The keys

KeysWhat they do
:42Go to line 42
42G or 42ggSame thing, without the command line
ggFirst line
G or :$Last line
:set numberShow line numbers

Lines count from 1, the same numbers you see with :set number turned on and in compiler errors. Each jump lands on the first non-blank character of the line.

To open a file at a line from the terminal, use vim +42 file.txt.

Related

Want all of Vim, in order? Vim Scoops is a free game that starts at h j k l and builds up to macros.

Play the full game