39

File:

i am someone1.
i am someone2.
i am someone3
~
~

Documentation says G takes me end of the file, but it only takes me to the beginning of last line. I want to be able to come to last character of the file, 3 in this case, and press a and type a period.

How do I do that?

1

7 Answers 7

43

If you type A after G you will enter insert mode at the end of the last line.

If you just want to go to the last character, then G-End will suffice

2
  • A then G is fine for me. But if I don't want to edit, is G-End the only option? Is there a single key to do this instead of two?
    – Animesh
    Feb 3, 2012 at 17:11
  • 3
    Not that I am aware of, but that is no guarantee. You can always create your own map if you like.
    – Bernhard
    Feb 3, 2012 at 17:17
40

G goes to the last line and $ goes to the last character of the line, so

G$
2
  • Gilles, Thanks this is more of what I was looking for.
    – Animesh
    Feb 4, 2012 at 0:58
  • Thanks. It's worth clarifying it's a capital G: Shift+g
    – forzagreen
    Jul 17, 2017 at 10:21
6

Ctrl+End also works, in both normal and insert modes. :help <C-End>

4
  • This only moves the cursor to the last character in the current line.
    – sebix
    Oct 6, 2015 at 11:15
  • @sebix: No, check the help. Oct 6, 2015 at 22:02
  • Does not work for me with vim 7.4
    – sebix
    Oct 7, 2015 at 13:01
  • @sebix: It works for me just fine, and the help text is pretty clear. Maybe you have some mapping or plugin that is overriding the built-in behavior. Oct 7, 2015 at 19:56
3
  • Move to last line in file: G
  • Move to first line in file: 1G
  • Move to end of line: $
  • Move to beginning of line: ^
1
  • 1
    Welcome to U&L, this hardly add anything to existing and accepted answer.
    – Archemar
    Jul 10, 2017 at 16:34
0

Most of the answers here assume a non-blank last line of the file - which is likely the most common case. There are also assumptions about the availability of an END key on one's keyboard. However, END keys are not universally available and blank lines are possible at the end of a file. Therefore the following can be leveraged for all cases to find the last (non-end-of-line) character of a file:

?[0-9a-zA-Z]

This is merely one of a few (or perhaps several) command combinations that can achieve the intended result. The pattern being:

"Set Cursor Position" + "Search Method" + "Pattern"

In the case of the above command sequence, you go to the beggining of the file and do a reverse search for any digit or letter.

0

Using Vimscript:

:call search('\%$')

Reference: :help \%$

%$ Matches end of the file.

-1

you can use large number such as 99 or 999 and $. like 999$

2
  • This is more keystrokes than G$ and less certain. Many files are longer than 1000 lines.
    – Wildcard
    Nov 22, 2017 at 23:45
  • Agree, but this solution open a possibility that you can position to the end of any lines, say you can position to the end of line 13. You can do 13$.
    – Fred Yang
    Dec 1, 2017 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.