I am trying to remap my hjkl keys to jklö. this is not a problem in most simple cases, but with commands like <C-w>h where you can specify an amount in the form of <C-w>{count}h or {count}<C-w>h this doesn't seem to work.

is there some way of doing a mapping like

nn <C-w>{count}j <C-w>{count}h
  • 1
    You might need langmap, but im not an expert there
    – D. Ben Knoble
    Aug 13 '19 at 12:11
  • 1
    @D.BenKnoble that does seem to work. i just used set langmap+=jklöJKLé;hjklHJKL Aug 14 '19 at 12:06
  • Feel free to self-answer
    – D. Ben Knoble
    Aug 14 '19 at 12:09

what worked for me was to use langmap.

set langmap=jklöJKLé;hjlkHJKL

this remaps the keys for all commands


Note that the correct way to type this command is {count}<C-w>h, with the {count} preceding the command. <C-w>h (and its friends) is a whole command on its own, so the count should precede it and not stand in the middle of the command.

And note that the following mapping:

nnoremap <C-w>j <C-w>h

will work for both <C-w>j and {count}<C-w>j.

But there are workarounds you can use.

Assuming it's unlikely you'll want to switch a double digit number of windows in any direction at any time, you could simply add mappings for single digit counts:

nnoremap <C-w>1j 1<C-w>h
nnoremap <C-w>2j 2<C-w>h
nnoremap <C-w>3j 3<C-w>h
nnoremap <C-w>4j 4<C-w>h
nnoremap <C-w>5j 5<C-w>h
nnoremap <C-w>6j 6<C-w>h
nnoremap <C-w>7j 7<C-w>h
nnoremap <C-w>8j 8<C-w>h
nnoremap <C-w>9j 9<C-w>h

You could keep going. And you could generate these programatically using a for loop as well...

If you want a more general solution than that, consider creating an <expr> mapping for <C-w> itself, which will read more characters (using getchar()), parse a {count} and a remaining command, mapping the "hjkl" commands according to your specification and issuing the final remapped command including the {count}. (Personally, I think that's overkill, but go for it if you feel like it!)

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.