Reputation: 9370
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?
Upvotes: 8
Views: 16502
Reputation: 398
I was trying to do the same. I found the answer in the following link: Traversing text in Insert mode.
For some reason still unknown to me, the Ctrl binding in insert mode didn't work for me. One alternative is by pressing Ctrl-O which switches to normal mode for one command, so <C-o>h
, <C-o>j
, <C-o>k
, <C-o>l
will let you move around while in insert mode. Alternatively, I have used the following mapping as I find it shorter than pressing <C-o>
plus h,j,k,l:
inoremap h<Tab> <Left>
inoremap j<Tab> <Down>
inoremap k<Tab> <Up>
inoremap l<Tab> <Right>
Upvotes: 0
Reputation: 16198
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.
Upvotes: 3
Reputation: 22616
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.
Upvotes: 8
Reputation: 62548
Pardon me for saying so, but how useful would be to have them work as in normal mode. I mean, what would you use for typing hjkl then?
But, if you really want to map them, sure, just map them with <imap> <something-h> <some operation>
and off you go.
Although I see no point. If you want to keep your hands on the middle of the keyboard, why not map jj to <Esc>
(some prefer that way, so they don't have to move their fingers off the home row).
Upvotes: 2