Go To End of File in Vim / Vi
The Short Answer:
G (shift + g) 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, G (shift + g) 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…
Delete from the line your cursor is on to the end of the file
Use dG in Normal mode
Delete from the line your cursor is on to the end of the file, and enter Insert mode
Use cG in Normal mode
Select from your cursor to the end of the file
Enter visual mode with v then navigate to the beginning of the last line with G.
Delete everything from the right of your cursor to the beginning of the last line
Use d]] 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 (shorten or lengthen) your selection
Use o 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 o 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 a matching parenthesis, bracket, or brace
If you’re editing a JSON file with mismatched brackets, you can go to the end of the file with G and check where that bracket lines up with % 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 dG and G. 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.
Related articles
Select all in Vim / Vi
Select all and copy, paste, or delete the contents
Copy & Paste in Vim / Vi
Copy (Yank), Paste (Put) and Cut (Delete) in Vim
Searching in Vim
Search forward, backward, case insensitive, and more
Show & Hide Line Numbers in Vim / Vi
Toggle absolute and relative line numbers
Undo & Redo in Vim / Vi
Keyboard shortcuts and summary of how Vim tracks changes
Vim Go To End/Start of Line
Go to the end or beginning of a line in Vim
Go To Line In Vim
Variety of approaches to go to lines
Go To Top of File in Vim
Learn how to jump the top of the file in Vim, then navigate, search, highlight, and delete.
Vim / Vi Page Up and Down Controls
Quick reference for Vim's page up and down controls
How to delete lines in Vim / Vi
The best answer depends on which mode you use
Vim Find And Replace
You can use either the substitute command or the slash and dot method to search for patterns and replace with different values.