Move cursor to end of file in vim

Vim

Vim Problem Overview


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.

Vim Solutions


Solution 1 - Vim

This is quicker. Just use this

:$

Solution 2 - Vim

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

Solution 3 - Vim

Hit Esc and then press: Shift + G

Solution 4 - Vim

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.

Solution 5 - Vim

Go to Top - Double g

Go to Bottom - Shift + g

Solution 6 - Vim

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)

Solution 7 - Vim

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. :)

Solution 8 - Vim

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.

Solution 9 - Vim

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

Solution 10 - Vim

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

Solution 11 - Vim

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

inoremap <F3> <Esc>GA

Solution 12 - Vim

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

Solution 13 - Vim

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

Solution 14 - Vim

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

:$ put +

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

Solution 15 - Vim

  • To go to the last line and preserve the column you are already in: Shift + g

  • To go to the end of the line after this move: Shift + $

We can combine those moves using Shift + g + $

Remember that g + g will return you to the beginning of the file.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1322720View Question on Stackoverflow
Solution 1 - VimkarthikView Answer on Stackoverflow
Solution 2 - VimtimssView Answer on Stackoverflow
Solution 3 - VimMohamed Ayoub BENJELLOUNView Answer on Stackoverflow
Solution 4 - VimhobbsView Answer on Stackoverflow
Solution 5 - VimfuatView Answer on Stackoverflow
Solution 6 - VimAlexDView Answer on Stackoverflow
Solution 7 - VimgreduanView Answer on Stackoverflow
Solution 8 - Vimbroc.seibView Answer on Stackoverflow
Solution 9 - VimSandeep AmarnathView Answer on Stackoverflow
Solution 10 - VimGiliView Answer on Stackoverflow
Solution 11 - VimTimView Answer on Stackoverflow
Solution 12 - VimXinyi XiangView Answer on Stackoverflow
Solution 13 - VimSergiy KolodyazhnyyView Answer on Stackoverflow
Solution 14 - VimSergioAraujoView Answer on Stackoverflow
Solution 15 - VimMostafa WaelView Answer on Stackoverflow