Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

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.

like image 516
Steven Lu Avatar asked Oct 03 '11 23:10

Steven Lu


People also ask

How do you move in insert mode?

If you want to type in text, you need to be in Insert mode. To move from Command mode to Insert mode, press "i" (no quotes). To move from Insert mode to Command mode, press "ESC" (the Escape key). NOTE: If your terminal doesn't have an ESC key, or the ESC key doesn't work, use Ctrl-[ instead.

Can you use arrow keys in vim?

Note: For scrolling in vim editor, you can utilize the arrow keys too, but hjkl keys usage will make you scroll faster in the vim editor.

How do I insert a line break in vim?

in my . vimrc for years. Press Enter to insert a blank line below current, Shift + Enter to insert it above. So simple!

How do I switch between insert modes in vim?

Type i to switch into insert mode so that you can start editing the file. Enter or modify the text with your file. Once you're done, press the escape key Esc to get out of insert mode and back to command mode.


1 Answers

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.

like image 88
sidyll Avatar answered Oct 07 '22 18:10

sidyll