Hello. I have been using Vim for a long time to edit very different texts: editing configs, writing code, as an external editor in a browser and email client ...
The editor is almost perfect, but there was one small “but”. In particular, enraged layout switching. Recently, in a personal conversation, we talked about the rakes on the path of using Vim, and I decided to jot down some kind of “margin notes”.
It would seem, well, there is this: pressed the combination, enter the Latin alphabet, pressed again - the Cyrillic alphabet. However, in normal mode, the stay in which takes at least 80% of the time, imposes its own prints. Okay, about langmap, I think everyone knows.
')
We register the following in ~ / .vimrc:
set langmap=;ABCDEFGHIJKLMNOPQRSTUVWXYZ,;abcdefghijklmnopqrstuvwxyz
And we can execute commands in the normal mode with the Cyrillic layout. True, to enter commands via <:> still need to switch the layout, which infuriated.
Then I remembered that the editor has its own switch.
set keymap=russian-jcukenwin
In more detail the technique was described, for example,
here .
It seems that the problem has been solved: the layout switches only in insert mode, and the commands are entered in Latin. But again, the problem: the built-in switch well conflicts with the x-ray very well. And the default <C - ^> combination is not particularly ergonomic.
Disable Xbox and rely entirely on Vim? In principle, this could go, but really did not want to. To call the editor, for a set of Cyrillic names in the terminal, it seemed to me a little overkill. For a while he enjoyed, was confused and swore.
So it will not work, again in Google. I found an interesting
article by Khrabrov Dmitry
DeXPeriX about the
vim-xkbswitch plugin written by him and Alexey
Radkov .
In short, the plugin does the following: when switching to normal mode, switches the system-wide layout (via xkb-switch, which must be installed in the system) to Latin, remembering the current layout, and when switching to insert mode, switches to the memorized one. To say that I was glad to say nothing. Many thanks to the authors for something that was lacking all these years.
However, in the process of exploitation, I encountered some difficulties. I went to my computer via ssh:
$vim file.txt Vim: Caught deadly signal SEGV Vim: Finished. zsh: segmentation fault vim file.txt
I didn’t immediately think about the plugin, there were thoughts about a sprinkled hard disk, a bad file system and similar “nice” things ... In general, xkb-switch with the unset variable DISPLAY drops out in segfault, and the plug-in follows it, carrying away and vim .
As a solution, you can check whether the variable is set and, only if successful, activate the plugin. It looks like this:
if $DISPLAY == "" let g:XkbSwitchEnabled = 0 else let g:XkbSwitchEnabled = 1 let g:XkbSwitchLib = '~/.local/lib/libxkbswitch.so' let g:XkbSwitchIMappings = ['ru'] endif
After this, the flights stopped. If you want to have the plug-in functionality when editing via ssh, then you need to connect with the support of X-forwarding, with the -X or -Y keys.
I hope this article will help save some nerve cells.
UPD: Made a pull request to the developer.