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

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

  • G without a count moves to the last line of the file
  • With a count, {N}G moves to line number N (e.g., 42G jumps 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 gg to jump to the first line of the file (the counterpart to G)
  • 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}G if you want to navigate back later with <C-o>
  • Combine with operators: dG deletes from the current line to the end of the file, yG yanks from the current line to the end
  • Use <C-o> to jump back to your previous position after pressing G
  • Use <C-g> or :f to see the current line number and total line count before jumping

Next

How do I edit multiple lines at once using multiple cursors in Vim?