Manel B
Manel B

Reputation: 313

How can I move the cursor to the end of the line in insert mode?

Is there an existing command or a configuration for my .vimrc that will make CTRL+right arrow go to the end of the line in insert mode instead of going to the next line? Like in most common editors, that shortcut jumps word by word, but in vim it goes to the next line when the cursor is at the last word in the line.

If there is a different fast way to jump to the end of the line in insert mode, that would also be useful.

Upvotes: 7

Views: 5201

Answers (2)

Thomas Dickey
Thomas Dickey

Reputation: 54505

The Home and End keys are usually interpreted by vim in insert-mode as beginning and end of line (like 0 and $), respectively.

This is documented in the ins-special-special topic, e.g.,

:h ins-special-special

Upvotes: 2

BenjaminRH
BenjaminRH

Reputation: 12172

In general, the best way to navigate in vim is in normal mode, and not in insert mode. I suggest that instead of finding ways to navigate in insert mode, you use the power of normal mode as intended. There are many ways to do this, but here are a couple of suggestions:

  • Use CTRL+o while in insert mode to temporarily enter normal mode for the next command, and then $ to go to the end of the line (after which you will be returned to insert mode)
  • Use ESC to return to normal mode, and then A which both moves the cursor to the end of the line and enters insert mode

If you want to navigate word by word (in normal mode), you can use w to move to the next word, or e to move to the end of the next word.

Upvotes: 13

Related Questions