I am in the slightly unusual position of using two different keyboard layouts on a regular basis (Programmers-Dvorak and Turkish-F). These layouts are quite different from each-other and I am only able to be proficient in vim with one set of muscle memories. I'm pretty proficient with vim commands in the Dvorak layout, but it's almost impossible to use if my keyboard is in the Turkish-F layout. Unfortunately I regularly edit files in both English and Turkish and even mixed languages. My proficiency is such that I can type either language in it's respective keyboard layout rather well, but my brain refuses to cross-wire them and type even a few letters of a word in Turkish from the Dvorak layout or vise versa.
I have two-key-salute bindings for changing the layout in Xorg, but even this leaves me with an awkward workflow in vim when editing mixed language files:
<vim commands…>i<switch to tr>…content…<escape><switch to en><vim commands…>
I would like to be able to shorten this to something like:
<vim commands…><leader>i…content…<escape><vim commands…>
...such that using <leader>i
sets a bunch of :imap
values to emulate the Turkish layout without changing the system keyboard layout. At the same time, i
would switch to insert mode but without the extra :imap
values. The values themselves are easy, I just need the alphabet mappings something like these:
:imap a u
:imap A U
:imap o i
:imap O İ
"etc.
The question is, how to setup two insert modes, one normal insert mode and one pseudo insert mode that is identical except for a bunch of mappings, and how can I trigger these modes with <leader>i
, <leader>a
, etc.?
InsertEnter
andInsertLeave
autocmds, which you can use to switch layouts automatically. Specifically, on theInsertLeave
you can check if it's Turkish, if it is, switch to Dvorak, set a flag, and when you enter insert again switch back to Turkish if that was the case last time you left insert mode.:imap
is that it would work even in a remote ssh session or when$DISPLAY
is otherwise not set.