Steven Lu
Steven Lu

Reputation: 43547

Vim: arrow keys to move within a line in insert mode

I have <Up> and <Down> nnoremapped to gk and gj but this won't let me use them while in edit mode. I tried using inoremap but that just types out gk or gj.

So I could certainly do something like inoremap <Up> <ESC>gki. Is this the best and only reasonable way to do it? I don't like this method because it isn't apparent to somebody reading the settings file what it does. Not that I could say that about any bit of vim setting file I have ever seen.

Upvotes: 9

Views: 488

Answers (1)

sidyll
sidyll

Reputation: 59307

To execute a normal mode command in insert mode, use Control+o. Straight from the help:

CTRL-O      execute one command, return to Insert mode   *i_CTRL-O*

So something like this:

inoremap <Up>   <C-O>gk
inoremap <Down> <C-O>gj

Might be more readable.

Upvotes: 8

Related Questions