Vim - Go to End of File

July 27, 2022

Introduction

When working on a large file in Vim, users often need to move around to edit different sections. While a keyboard is efficient with short texts, it’s not the best choice for extensive documents.

Vim is equipped with functional tools for navigating big files, including jumping to the top or bottom of a file.

This guide will show you how to go to the end or top of a file in Vim.

How to Go to End or Top of File in Vim

Note: To execute commands, Vim needs to be in normal mode. Press Esc to switch to normal mode.

How To Jump to the End of the File

Moving to the end of a file is slow when using arrow keys only. Luckily, Vim offers several ways to quickly reach the bottom of a file.

Note: Commands in Vim are case sensitive.

1. Jump to the Last Line

Use the G key to jump to the last line. The output shows the cursor at the last line:

Vim The G Key Terminal Output

2. Use the End Key

The G key moves the cursor to the final line but not to the end of that line. So, to jump to the end of a line, use the Ctrl and End keys:

Vim Ctrl and End Keys Terminal Output

3. Append/Insert Text at the End

Move to the bottom of the file and switch to insert mode with G + A.

Unlike G, this command sends the cursor to the end and allows users to add, edit, or delete text.

Vim G and A Keys Terminal Output

4. Run the $ Command

The $ command shifts the cursor to the end. Switch to normal mode and execute:

:$
Vim the $ Command Execution

Hit Enter and the cursor shifts to the end:

Vim the $ Command Terminal Output

5. Use the Closed Brackets

Typing the double-closed brackets when in normal mode moves the cursor to the end:

Vim Closed Brackets Terminal Output

The terminal displays the last line as soon as the user types ]] - there is no need to hit Enter in this case:

Vim The Closed Brackets Terminal Output

How To Jump Back to the Top of the File

Vim offers several ways to move back to the start of a file. Here are some useful methods.

1. Go to the Beginning of the File

Getting back to the beginning of a file is quite simple. One way is to type 1G:

Vim 1G Terminal Output

2. Use the gg Keystroke

Typing gg gives the same output as the previous command:

Vim gg Terminal Output

3. Use the Home Button

Another way to jump to the top is to use the Home button. Much like jumping to the end, this key only works when combined with Ctrl.

Use Ctrl + Home to perform this action:

Vim Ctrl and Home Terminal Output

4. Jump to the Start with Open Brackets

Move to the start of a file quickly with double-open brackets. Hit Esc to switch to normal mode and type [[:

Vim Open Brackets Terminal Output

After typing both brackets, the cursor jumps to the top.

5. Go to the First Line

Moving through text using line numbers is a practical way to jump to the start of a file. However, this is not an efficient way to jump to the end of a file.

But, the first line is always Line 1. Therefore, use this command to move the cursor to the first line instantly:

:1
Vim the 1 Command Terminal Output

Hit Enter and the cursor jumps to the beginning:

Vim 1 and Enter Terminal Output

6. Append/Insert Text at the Beginning

Move to the top and start editing the text with gg+A. This key combo moves the cursor to the first line and enters you into insert mode.

Vim gg and A Terminal Output

Moving Through a File in Vi/Vim - Overview

Knowing how to move in Vim and jump to the top or bottom of the text is useful when handling large documents.

Make sure to hit the Esc key to switch to normal mode before running any command. The table below shows all the ways to go to the beginning or end of a document in Vim:

OptionDescription
GJumps to the beginning of the last line of the file.
ggShifts to the beginning.
]]Moves the cursor to the end.
[[Moves the cursor to the start.
G + AGoes to the end of the file and switches to the insert mode.
gg+AShifts to the top and switches to the insert mode.
Ctrl + HomeDisplays the top of the text.
Ctrl+EndDisplays the very end of the text.
:1Jumps to the first line.
:$Moves the cursor to the end of the file.
1+GJumps to the top of the file.

Conclusion

This tutorial explained how to move to the top or end of the file in Vim. Now you know how to navigate a text in Vim using different methods.

Next, learn how to save a file in Vim and exit the text editor.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
How to Search to Find a Word in Vim or Vi Text Editor
July 31, 2020

Searching in Vim or Vi allows you to easily navigate through large files. This guide teaches you how to search for a word or pattern and move through the search results, with or without case sensitivity...
Read more
How to Change and Use Vim Color Schemes
March 9, 2020

Vim color schemes are a handy feature for setting syntax highlighting. You can choose from a wide variety of ready-made themes or configure your own color set and highlight preference. This article shows you everything you need...
Read more
How to Search to Find a Word in Vim or Vi Text Editor
July 31, 2020

Searching in Vim or Vi allows you to easily navigate through large files. This guide teaches you how to search for a word or pattern and move through the search results, with or without case sensitivity...
Read more
Vim Commands Cheat Sheet
July 22, 2020

Vim is an open-source text editor found in most Linux distributions. This article lists all the commonly used Vim commands and includes a downloadable one-page cheat sheet for future reference...
Read more