Go to the Beginning or End of the File in Vim

In this quick Vim tip, learn how to quickly move to the end or beginning of a file.
Warp Terminal

While making changes to the configuration file, most users will add new lines at the end of the file. Sure you can use the down arrow key multiple times to get there but that's not practical.

The same goes for going to the beginning of the file!

But Vim is one of the most powerful text editors, you are already given multiple options to jump to the beginning or to the end of the file in Vim.

First press the Esc key to switch to the normal mode and then use the following actions to get the desired output:

Action Description
gg or [[ Go to the beginning of the file.
Ctrl + End Go to the end of the file.
Shift + g or ]] Jump to the beginning of the last line.

Want more details? Here you have it.

Go to the beginning of the file in Vim

I assume you already have opened the file inside Vim and if you didn't, you can use the vi command in the following manner to do so:

vi Filename

Press the Esc key to switch to the normal mode which will allow us to use Vim keybindings.

Now, there are two ways you can go to the beginning of the file in Vim:

  1. By pressing gg
  2. By pressing [[

Sure, you can also use 1G but it requires you to first press 1 and then Shift + g (to press trigger capital G) which is not productive in any way.

Once you use any of the shown ways, it will land you at the beginning of the file:

jump to the beginning of the file in vim

As you can see, no matter where I was, once I pressed [[, it skipped the cursor to the beginning of the file.

Go to the end of the file in Vim

To go to the end of the file, all you have to do is press Ctrl + End and it will get you to the end of the file:

Go to the end of the file in Vim

Pretty easy. Right?

Go to the last line in Vim

There are times when you want to skip to the last line but to the initial part and in that case, you have two options:

  • Press ]]
  • Press Shift + g (to trigger capital G)

Once you use any of these shown ways, here's what you should expect:

Go to the beginning of the last line in Vim

Pretty easy. Right?

Beginner to Vim? Let me help

The new Vim users are often overwhelmed with the amount of keybindings and different workflow compared to other text editors like Nano.

To tackle this situation, we made a beginner's guide to the Vim editor addressing all the basic parameters of Vim to kickstart your journey:

Editing Files With Nano in Linux [With Cheat Sheet]
Though Nano is less complicated to use than Vim and Emacs, it doesn’t mean Nano cannot be overwhelming. Learn how to use the Nano text editor.

Here's a cheat sheet to the Vim keybindings:

Awesome Vim Cheat Sheets to Help You Learn Vim
A useful collection of Vim cheat sheets to help you learn Vim editor faster. You can use them and download them for free.

I hope this will help you become a better Vim user (so you can flaunt your Vim skills).

About the author
Sagar Sharma

Sagar Sharma

A software engineer who loves to write about his experience with Linux. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.

It's FOSS

Making You a Better Linux User

It's FOSS

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.