13

I type with a non-QWERTY keyboard layout. Many of the keys Vim uses are now on the home row, but some key bindings just don't work, the most obvious one being the hjkl keys.

How and where can I change these key bindings to work better with my keyboard layout?

10
:help langmap

You can remap keys in command mode but leave them intact for typing. This means you can use the intent of hjkl - adjacent homerow keys for scrolling - by pressing the positional equivalents on your keyboard. Suppose your layout is Dvorak, then those same keys are dhtn. We need to map all four, even h:

:set langmap=dh,hj,tk,nl

You can now navigate using dhtn. This won't affect :commands like this and won't change insert mode (i.e. pressing t will give you a 't').

You'll need to map other keys too for normal mode - for instance, the delete action would normally be d but that's now a navigation key. j, k or l might work since they're no longer navigation keys.

2
  • 1
    To be fair, Dvorak uses the keys dhtn, not htns, in the place where Qwerty uses hjkl.
    – Anthony
    Feb 21 '15 at 17:26
  • Thanks @Anthony, I've updated the langmap command to match.
    – David Lord
    Apr 29 at 3:42
2

You can remap keys in vim. nnoremap [ h remaps [ to h, so you can use [ in place of h, you could remap h to what [ originally did for it to be complete. You'd have to do this for all keys though and there are different modes to consider, so I guess it would be a bit of a pain.

2
  • Since I'll be using vim for at least the next 10 years I'd think it worth the investment. Where do I use this for the change to be reasonably permanent?
    – Earthliŋ
    Feb 4 '15 at 1:49
  • 1
    you should put this in your ~/.vimrc Feb 4 '15 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.