Question

I want to map the following for navigation in insert mode :

  • <c-h> # Move left
  • <c-j> # Move down
  • <c-k> # Move up
  • <c-l> # Move right

So, I added the following to my .vimrc :

inoremap <c-h> <left>
inoremap <c-j> <down>
inoremap <c-k> <up>
inoremap <c-l> <right>

Now,

  • Left doesn't work [ Instead it deletes the left character ]
  • Right works !
  • Up works !
  • Down works !

As I understand, <c-h> by default deletes left character. But I am unable to override it.

I even tried this :

 inoremap <c-j> <down>
 inoremap <c-k> <up>
 inoremap <c-l> <right>
 " Re-mapping <c-h> for insert-mode
 autocmd InsertEnter call RemapCtrlH()
 function RemapCtrlH()
     iunmap <c-h>
     inoremap <c-h> <left>
 endfunction

But even this didn't work either.

Was it helpful?

Solution

So, I added the following to my .vimrc :

inoremap <c-j> <down>
inoremap <c-j> <down>
inoremap <c-k> <up>
inoremap <c-l> <right>

Your first and second lines are the same! Change the first to the following:

inoremap <C-H> <Left>

You can confirm your mapping with:

:verbose imap <C-H>

Update following update to question, comments and acceptance

I've left the information above untouched, but to respond to the comments...

  1. The clash with your "autoclose" plugin explains why this worked in the editor but not in $MYVIMRC. You could work around this by putting your mapping in a plugin file in an after-directory.

  2. I used title case for the <C-H> mapping consistent with the notation in the official documentation. The documentation states:

    The case of {char} does not matter; thus CTRL-A and CTRL-a are equivalent.

    Should you wish to map CTRL-Shift-H, use inoremap <C-S-H> instead.

  3. I'm delighted :verbose map helped you to track down the source of your problem! :verbose is a handy tool when debugging Vim scripts.

Good luck!

OTHER TIPS

My solution:

inoremap <c-p> <up>
inoremap <c-n> <down>
inoremap <c-b> <left>
inoremap <c-f> <right>

Advantage: they're widely used in all programs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top