How do I jump to the last line of a file in Vim?
Answer
G
Explanation
The G command moves the cursor to the last line of the file. It is one of the most fundamental navigation commands in Vim and is used constantly when working with files of any size.
How it works
Gwithout a count moves to the last line of the file- With a count,
{N}Gmoves to line number N (e.g.,42Gjumps to line 42) - The cursor lands on the first non-blank character of the target line
Example
Given a file with 500 lines, pressing G from anywhere in the file instantly moves the cursor to line 500.
To jump to line 100, press 100G.
Tips
- Use
ggto jump to the first line of the file (the counterpart toG) - Use
:{N}(e.g.,:100) to jump to a specific line number, but note that this does not add an entry to the jump list — prefer{N}Gif you want to navigate back later with<C-o> - Combine with operators:
dGdeletes from the current line to the end of the file,yGyanks from the current line to the end - Use
<C-o>to jump back to your previous position after pressingG - Use
<C-g>or:fto see the current line number and total line count before jumping