Terminus by Warp
Go To End of File in Vim / Vi

Go To End of File in Vim / Vi

Preston Tunnell Wilson
Preston Tunnell Wilson
Senior Software Engineer, InStride Health

[#the-short-answer]The Short Answer:[#the-short-answer]

[.inline-code]G[.inline-code] ([.inline-code]shift + g[.inline-code]) goes to the end of the file

This movement works in both visual and normal mode.

Some Additional Options

Learning more about Vim might feel like learning more about four different tools in one toolbox:

  • Insert mode
  • Normal mode
  • Visual mode
  • Ex mode

Insert mode is where you, well, insert the majority of your code and content, but it’s not the most efficient for navigation and operations. Since Normal mode and Visual mode aren’t as concerned with adding individual characters to files, they can swap some keys on the keyboard optimized for that functionality.

Specifically, [.inline-code]G[.inline-code] ([.inline-code]shift + g[.inline-code]) goes to the beginning of the last line of the file in both Normal and Visual mode. You can combine this movement with a command or use it to navigate.

Let’s check out some examples…

[#from-current-line]Delete from the line your cursor is on to the end of the file[#from-current-line]

Use [.inline-code]dG[.inline-code] in Normal mode

[#enter-insert-mode]Delete from the line your cursor is on to the end of the file, and enter Insert mode[#enter-insert-mode]

Use [.inline-code]cG[.inline-code] in Normal mode

[#from-cursor-to-end]Select from your cursor to the end of the file[#from-cursor-to-end]

Enter visual mode with [.inline-code]v[.inline-code] then navigate to the beginning of the last line with [.inline-code]G[.inline-code].

[#right-of-cursor-to-beg-of-last-line]Delete everything from the right of your cursor to the beginning of the last line[#right-of-cursor-to-beg-of-last-line]

Use [.inline-code]d]][.inline-code] in Normal mode. If you need to join the current line with the last line, this is an option for you. But the situation probably won’t arise frequently.

[#edit-your-selection]Edit (shorten or lengthen) your selection[#edit-your-selection]

Use [.inline-code]o[.inline-code] to jump from either side of your selection to the other. Let’s say that you go into Visual mode and quickly navigate to the bottom of the file. After you do so, you realize that you’ve selected too much! You can hit [.inline-code]o[.inline-code] to navigate back to the beginning of the selection, move the selection to the proper starting point, all while keeping the end of the selection at the end of the file.

[#find-matching]Find a matching parenthesis, bracket, or brace[#find-matching]

If you’re editing a [.inline-code]JSON[.inline-code] file with mismatched brackets, you can go to the end of the file with [.inline-code]G[.inline-code] and check where that bracket lines up with [.inline-code]%[.inline-code] in Normal mode.

This long list is actually most of the iceberg—most of the commands that I run for navigating or editing the end of the file are simply [.inline-code]dG[.inline-code] and [.inline-code]G[.inline-code]. If you want to dive into more information on going to the end of files (and a whole lot more), check out the official Vim documentation or our collection of Vim tips and tricks.

Experience the power of Warp

  • Write with an IDE-style editor
  • Easily navigate through output
  • Save commands to reuse later
  • Ask Warp AI to explain or debug
  • Customize keybindings and launch configs
  • Pick from preloaded themes or design your own