The default keybinding of vim were quite obviously created with the US keyboard layout in mind, which make some of the default ones rather awkward on non-US keyboards. For example on my Hungarian keyboard [ and ] are altgr+f and g respectively, while the physical place of [ and ] are occupied by special accented characters ő and ú. I realized, that although in insert mode I obviously need these to be able write quickly in Hungarian, in normal mode I can map these keys back to [ and ] and make my life easier and sort-of keep the default vim bindings in terms of physical placing.

So now I have in my .vimrc:

nmap ő [
nmap ú ]

To test this I turned to two commands Ctrl-] and g]. Both Ctrl-] and Ctrl-ú now jump to the appropriate tag. Unfortunately, g] does open a list of tags, but doesn't do anything.

Any idea why one of these work, while the other does not?

EDIT: For fellow Hungarians, based on the perfect answer below, I now have this in my .vimrc:

set langmap=ő[,ú],á',é`,ű#

I believe the 'langmap' option can help you here. It translates keys when they're used in Normal mode and similar contexts.

Try the following setting:

set langmap=ő[,ú]

UPDATE: From feedback of the author of the question, this would be a 'langmap' setting covering all special keys in a Hungarian keyboard layout:

set langmap=ő[,ú],á',é`,ű#

If this works correctly, it should also take care of commands with more than one character (g], [[, etc.) and marks ('[ and ']).

The reason why the approach using nmap doesn't work is that it only covers full commands, mappings don't really apply in the middle of other commands. They're not really meant for translating a whole key, that's why options such as 'langmap' exist.

I was somewhat surprised that you mentioned that Ctrl-ú already worked. I'm guessing this happens even without any settings. I imagine your keyboard driver already sends a Ctrl-] when Ctrl-ú is pressed, given the typical location of that key on your keyboard layout. You could easily confirm that by entering Ctrl-V followed by Ctrl-ú in Insert mode and seeing what it produces. If this hypothesis is correct, you'll see ^] which is the sequence that represents Ctrl-].

  • 1
    Ctrl-ú actually works in select mode as well. Strange. I will try langmap, and report back :) – fbence Dec 9 '20 at 15:42
  • 2
    Ok, this was exactly what I needed! – fbence Dec 9 '20 at 15:43
  • 2
    I do have to say I'm always amazed how good vim is ... – fbence Dec 9 '20 at 15:52

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.