I don't want to change the default position of my right hand to use the direction keys, also I'd like to be able to use them in the insert mode.

So I've got the following part in my .vimrc file:

" Move cursor keys `h`, `j`, `k`, `l` one position to the right
noremap ; l
noremap l k
noremap k j
noremap j h

" Alt + j, k, l, ; for cursor movement in the insert mode
" Bind `Alt + k` with `<M-k>`. If not to do so the mapping won't work :(
execute "set <M-k>=\ek"
inoremap <M-k> <Down>
execute "set <M-l>=\el"
inoremap <M-l> <Up>
execute "set <M-;>=\e;"
inoremap <M-;> <Right>
execute "set <M-j>=\ej"
inoremap <M-j> <Left>

But I have the following bug:

When I'm in the insert mode I'm changing the cursor position with Alt+j, Alt+k, Alt+l and Alt+; then I switch to the normal mode with Esc. Then the following happens: I decide to move the cursor, for example, up (the same is true for all other directions), and I press l. The cursor moves up. Then I press l one more time. Vim switches to the insert mode and the letter l is printed. (Note: If I press "Esc" several times to switch to the normal mode, everything works as expected: I continue to move up whithout switching to the insert mode with the l letter being printed)

What could be the reason for the bug and how can I fix it?

  • I ran Neovim v0.10.0-dev with your config and it worked properly. No unexpected switch to insert mode. I am assuming you are new to Vim, so please don't take this the wrong way, but most people prefer to get used to the default hjkl direction keys rather than re-map them. It might be tricky at first, but using a tool the same way as everyone else often has benefits down the road. That said, it's OK to decide to remap the keys like this if it works for you. In the event that you are in fact new to Vim, I would recommend starting out with Neovim so you don't eventually have to migrate later on.
    – nullromo
    Apr 10 at 21:41
  • @nullromo I've been using Vim for over a year. It asways annoyed me that to change the cursor position you need to switch between insert and nomal modes + move your right hand one key to the left. Regarding my problem I assume that it's related to the specifics of how the terminal works on my system.
    – Fyodor
    Apr 13 at 11:40
  • Yes, it may have to do with other parts of your setup. For the record, I tried it using WSLTTY. And also I usually press both h and j with my right index finger rather than moving my whole hand over 1 key. But in the end whatever works for you is best.
    – nullromo
    Apr 14 at 22:38


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.