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:
- By pressing
gg
- 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:
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:
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:
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:
Here's a cheat sheet to the Vim keybindings:
I hope this will help you become a better Vim user (so you can flaunt your Vim skills).