26

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?

32

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

  • 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 '12 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 '12 at 17:17
30

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

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

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

  • This only moves the cursor to the last character in the current line. – sebix Oct 6 '15 at 11:15
  • @sebix: No, check the help. – Kurt Hutchinson Oct 6 '15 at 22:02
  • Does not work for me with vim 7.4 – sebix Oct 7 '15 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. – Kurt Hutchinson Oct 7 '15 at 19:56
0
  • 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
    Welcome to U&L, this hardly add anything to existing and accepted answer. – Archemar Jul 10 '17 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:

G?.

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 end of the file and do a reverse search for any character (but not an 'end of line' character).

-1

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

  • This is more keystrokes than G$ and less certain. Many files are longer than 1000 lines. – Wildcard Nov 22 '17 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 '17 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.