453
votes

When I want the cursor to go to the end of the file (i.e. the end of the last line) in Vim, I have to type six keystrokes:

<ESC>G$a - which translates to ESC + Shiftg + Shift4 + a on my keyboard layout.

How can I do this more efficiently?

Since I regularly work on many different machines, I cannot always change .vimrc, so I'm looking for answers without having to edit or create that file.

14
Just want to point out, the commands you're showing should be represented as follows: <esc>G$a, you show the shift by making the letter uppercase. And you show a $ instead of shift + 4, since no matter the keyboard the function of this key ($) won't change, but if you do shift + 4 then the meaning can change. :)greduan
@Eduan I generally agree, but in this case actualy keypresses are also relevant. I added both :-)timss
@Eduan For the question of efficiency, the actual commands don't matter. The keystrokes do. And since there are huge differences in keyboard layout between languages, I don't know where the $ is on a US keyboard, and it might well be that for Americans entering the command $ is just one keystroke. I wanted to explicitly show that for me (with a German keyboard) it is two keystrokes.user1322720
@what IC. I can understand that. Just wanted to point it out so in the future you know. :)greduan

14 Answers

561
votes

This is quicker. Just use this

:$
452
votes

No need to explicitly go to the end of line before doing a, use A;
Append text at the end of line [count] times

<ESC>GA

138
votes
44
votes

For starters, there's no need for the return. G$ will do. And you're being misleading by counting <Esc> and a in the length of a normal mode command.

However, you can use Ctrl + End if you like.

34
votes

Go to Top - Double g

Go to Bottom - Shift + g

26
votes

I thought the question was "Move cursor to end of file in vim" ?

End-of-file: Esc + G
Begin-of-file Esc + g (or gg if you are already in the command area)

24
votes

The best way to go to the last line of the file is with G. This will move the cursor to the last line of the file.

The best way to go to the last column in the line is with $. This will move the cursor to the last column of the current line.

So just by doing G$ you get to the end of the file and the last line.

And if you want to enter insert mode at the end of the file then you just do GA. By doing this you go to the last line of the file, and enter insert mode by appending to the last column. :)

11
votes

If you plan to write the next line, ESCGo will do the carriage return and put you in insert mode on the next line (at the end of the file), saving a couple more keystrokes.

7
votes
  • Ctrl + Home = Jump to start of file
  • Ctrl + End = Jump to end of file
7
votes

Try doing SHIFT + G and you will be at the end of the page, but you can't edit yet. Go to the top by doing G + G

2
votes

You could map it to a key, for instance F3, in .vimrc

inoremap <F3> <Esc>GA
0
votes

I have been looking for the way to move the cursor to the end of a line and then edit on a mac terminal, here was how it worked for me. Exit your edit mode, type in g_(that's 'g' then underscore with no colon in the front), then simply press the 'a' key so you could "add" code to your scripts

0
votes

Another alternative:

:call cursor('.',strwidth(getline('.')))

This is may be useful if you're writing a function. Another situation would be when I need to open a specific template and jump to end of first line, I can do:

vi +"call cursor('.',strwidth(getline(1)))"  notetaking_template.txt

The above could also be done with

vi +"execute ':normal! $'" notetaking_template.txt

See also:

vim - Get length of the current line

0
votes

If you want to paste some clipboard content at the end of the file type:

:$ put +

$ ............ last line
put .......... paste 
+ ............ clipboard