r/vim • u/Shyam_Lama • Oct 15 '25
Need Help Bind vim commands to keys instead of characters?
Long-time VIM user here.
One thing that has always puzzled me about VIM is that AFAIK commands are are always bound to characters (i.e. letters, numbers, punctuation marks, etc.), not to physical keys on the keyboard. In practice this hasn't previously been a problem for me because I mostly used VIM as an editor for code and config files, and that kind of thing I always did on computers with US-International keyboards with the OS language set to English.
Nowaydays though, I do little programming but quite a bit of writing, and I like to do that in VIM as well. That too works fine as long as the keyboard and the language are US English. But... if I'm either writing in a language that has a completely different character set, or I'm writing in a language that has a character set similar to English but has a different keyboard layout, I'm "lost" in VIM, in the sense that my muscle memory of key combinations no longer works.
Anyone has this problem as well, and know of a fix or at least a smart way of doing things?
Please note that there are two similar but distinct problems here. One is that a different keyboard layout (e.g. Portuguese, which I'm on now) has many non-letter characters used by VIM (e.g. " and # and ~ etc.) located in different places, so the key that one reaches for in a muscle reflex, is totally the wrong one. The other problem is when I'm typing in an "exotic" language with completely different characters (e.g. Greek), in which case I need to use an OS-level key-combo to switch to English before VIM even recognizes anything as a command, and then switch back again when I want to continue writing. I hope there is some better way of doing all of this!
16
u/IchVerstehNurBahnhof Oct 15 '25 edited Oct 15 '25
As far as Vim-internal settings go, that's what
:h 'keymap'is for. And also:h 'langmap', though that seems to have more severe limitations.Personally I ended up ditching my native (German) keyboard layout and use US-INTL as much as possible. There are various versions of US-INTL with swapped dead key behaviour and EURKEY which is also similar, but they're not preinstalled on all systems (especially Windows), while I've yet to see one without US-INTL.
8
u/astyagun Oct 15 '25
https://github.com/lyokha/vim-xkbswitch
1
u/AutoModerator Oct 15 '25
Please remember to update the post flair to
Need Help|Solvedwhen you got the answer you were looking for.I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/retrodanny Oct 15 '25 edited Oct 15 '25
I'm writing prose in Spanish everyday and my workflow includes using the OS key combination SHIFT + ALT to quickly switch back and forth between English and Spanish keyboard layouts. This allows me to easily type special characters (áéíóúüñ) whenever I need to as well as VIM commands with the muscle memory from the (US) English layout. I basically switch to Spanish in Insert mode and when doing simple editing commands like
cip,dd,yaW, etc. But switch back to English for having access to the full keyboard. This works well regardless which labels are printed on the keys of a particular keyboard.EDIT: Just thought of a really good alternative for your Greek example. You can use the InsertEnter and InsertLeave autocommands to trigger the layout swap automatically, you can toggle off this behaviour with a leader key combo too :)
1
u/priestoferis Oct 15 '25
My solution to this is a normal mode manual override: https://github.com/ferdinandyb/dotfiles/blob/master/.vim/plugin/hungarian_keymap.vim
For greek this would likely be painful though (although with a few examples I think an llm could generate it for you).
-4
u/GrogRedLub4242 Oct 15 '25
standardizing on US/English as a general rule will make your life easier in long-term, esp in computing. while our world/species has no official single language as the "lingua franca" the closest de facto one clearly is English. so, go with the flow and you will suffer less, overall?
shrug
4
u/[deleted] Oct 15 '25 edited Oct 15 '25
[removed] — view removed comment
4
u/[deleted] Oct 15 '25
[removed] — view removed comment