Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What keys do you map <left>, <down>, <up>, <right> commands in VIM insert mode?

Tags:

vim

In Vim it is nice to use hjkl in normal mode and would be great to continue to use them in insert mode. I tried to map them to Ctrl-h, Ctrl-j, Ctrl-k, Ctrl-l:

 imap <C-h> <left>
 imap <C-j> <down>
 imap <C-k> <up>
 imap <C-l> <right>

but it is not convenient especially because it masks Ctrl-H and backspace stops responding. Have you been able somehow to use HJKL keys for movements in insert mode?

like image 277
dimus Avatar asked Aug 21 '10 16:08

dimus


People also ask

How do I navigate in Vim Insert mode?

To go into INSERT mode from COMMAND mode, you type i . To go back to COMMAND mode, you type the esc key. vim starts out in COMMAND mode. Over time, you will likely spend more time in COMMAND mode than INSERT mode.

How do I map a key to a Vim command?

Creating keymaps To map a sequence of keys to execute another sequence of keys, use the ':map' command. For example, the following command maps the <F2> key to display the current date and time. The ':map' command creates a key map that works in normal, visual, select and operator pending modes.


2 Answers

I'm using double upper case mapping in insert mode for various mapping. That works pretty well, except when you are pasting text from somewhere. It's usually wiser to clear all insert mappings before inserting text.

So you can try

imap HH <left>
imap JJ <down>

etc...

Obviously , you will need twice key strokes as the normal move, so I guess if you need to navigate "far away" it's better to go back in navigation mode.

like image 97
mb14 Avatar answered Oct 22 '22 11:10

mb14


I have mapped my normal mode arrow keys to 'bubble' text around. It is very useful for moving blocks of code or text around with minimal effort.

" Useful bubble text normal mapping for arrow keys.                                                                                        
nnoremap <UP> ddkP 
nnoremap <DOWN> ddp
vnoremap <DOWN> xp`[V`]
vnoremap <UP> xkP`[V`]

Definitely inspired by Drew Neil's episode on Bubbling Text on VimCasts.org.

like image 33
Tom Cammann Avatar answered Oct 22 '22 11:10

Tom Cammann