Monsieur Pierre Doune
Monsieur Pierre Doune

Reputation: 737

Vim Bindings Based on Key Position

Is it possible to make Vim recognize bindings by the actual key positions, not by inputted symbols? If I change my layout, I can't use any bindings.

Let's say I switch my layout to Russian and I want Ш act like an I.

Old dirty keyboard.

Upvotes: 0

Views: 845

Answers (2)

Monsieur Pierre Doune
Monsieur Pierre Doune

Reputation: 737

I've solved my problem with xkblayout-state: I just switch my system language layout with it every time I open Vim or enter a normal mode by these autocompletes:

" `0` is `en_US` in my case.
au VimEnter * silent !xkblayout-state set 0
au InsertLeave * silent !xkblayout-state set 0

Also I've found another solution on Vi Stack Exchange:

To use langmap in greek you can follow the example given in :h 'langmap' adding this line to your vimrc (Copying this line from here may not be a good idea since I'm really not sure of the encoding, yanking the line directly from the help file is probably safer):

langmap=ΑA,ΒB,ΨC,ΔD,ΕE,ΦF,ΓG,ΗH,ΙI,ΞJ,ΚK,ΛL,ΜM,ΝN,ΟO,ΠP,QQ,ΡR,ΣS,ΤT,ΘU,ΩV,WW,ΧX,ΥY,ΖZ,αa,βb,ψc,δd,εe,φf,γg,ηh,ιi,ξj,κk,λl,μm,νn,οo,πp,qq,ρr,σs,τt,θu,ωv,ςw,χx,υy,ζz

Upvotes: 4

Matt
Matt

Reputation: 15081

The positional key codes are called scan codes and are used and processed in hardware and low-level system software. You can't do anything with them in a portable application.

In principle, it's possible to go the other way and to map Russian/Cyrillic letters to the corresponding normal mode commands, like nnoremap ш i etc. However, that does not make much sense.

The point is that Vim already has built-in support for international key mappings in insert/replace mode. Simply add set keymap=russian-jcukenwin to vimrc and use Ctrl6 in insert mode to switch between the layouts.

In normal mode you should always stick to US/Latin. No need for system language switch.

Upvotes: 3

Related Questions