How do I move to end of line in Vim?

Viewed 907560

I know how to generally move around in command mode, specifically, jumping to lines, etc. But what is the command to jump to the end of the line that I am currently on?

15 Answers

Just the $ (dollar sign) key. You can use A to move to the end of the line and switch to editing mode (Append). To jump the last non-blank character, you can press g then _ keys.

The opposite of A is I (Insert mode at beginning of line), as an aside. Pressing just the ^ will place your cursor at the first non-white-space character of the line.

As lots of people have said:

  • $ gets you to the end of the line

but also:

  • ^ or _ gets you to the first non-whitespace character in the line, and
  • 0 (zero) gets you to the beginning of the line incl. whitespace

If your current line wraps around the visible screen onto the next line, you can use g$ to get to the end of the screen line.

I can't see hotkey for macbook for use vim in standard terminal. Hope it will help someone. For macOS users (tested on macbook pro 2018):

fn + - move to beginning line

fn + - move to end line

fn + - move page up

fn + - move page down

fn + g - move the cursor to the beginning of the document

fn + shift + g - move the cursor to the end of the document

For the last two commands sometime needs to tap twice.

Press A to enter edit mode starting at the end of the line.

The advantage of the 'End' key is it works in both normal and insert modes.

'$' works in normal/command mode only but it also works in the classic vi editor (good to know when vim is not available).

Also note the distinction between line (or perhaps physical line) and screen line. A line is terminated by the End Of Line character ("\n"). A screen line is whatever happens to be shown as one row of characters in your terminal or in your screen. The two come apart if you have physical lines longer than the screen width, which is very common when writing emails and such.

The distinction shows up in the end-of-line commands as well.

  • $ and 0 move to the end or beginning of the physical line or paragraph, respectively:
  • g$ and g0 move to the end or beginning of the screen line or paragraph, respectively.

If you always prefer the latter behavior, you can remap the keys like this:

:noremap 0 g0
:noremap $ g$

Or there's the obvious answer: use the End key to go to the end of the line.

Possibly unrelated, but if you want to start a new line after the current line, you can use o anywhere in the line.

Related