Home VIM Vim and Cyrillic: A couple of tricks

Vim and Cyrillic: A couple of tricks

by admin

Vim and Cyrillic: A couple of tricks
In the past, when editing ordinary Russian texts, I usually put aside Vim and resorted to other editors. This was caused by a couple of very annoying bugs :

  1. For every sneeze I had to switch the layout a hundred times in order to enter a couple of commands correctly and go back. For example, replacing a typed letter in a newly written word, resulted in : switch → get to the letter, press r → switch → [desired letter] → switch → A → [write next]. Hell!
  2. The built-in spell checker didn’t like the letter “e” and suggested replacing any word with an “e”. And I love the “e”, it made me sad.

So, I finally found a solution to both problems. I’m sitting now and typing this text in Vim. Curiously enough, both barriers are handled by regular means, without additional plugins. Since there are more materials in English than in Russian, it was not easy for me to find this information. Therefore, I want to share it with those who are interested.

Switching Layout

I’ve seen a lot of suggestions to re-map Cyrillic characters to Latin letters like this :
map th q
map c w
map y e
map to r
map e t
map n y
"... etc.

I didn’t like this solution because it left several problems. For example, you can’t re-map the punctuation, so colons and slashes in the Russian layout move to new places anyway. Also in paste mode, you can not use combinations like Ctrl+W or Ctrl+R. All this was annoying.
Need another solution and there it is! In .vimrc:
set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0
highlight lCursor guifg=NONE guibg=Cyan

Now for the clarification. Vim has a thing called lmap. It sets the conversion for all cases where we are talking about entering characters as part of text, but not as part of a command. So lmap is taken into account when pasting, typing search patterns, after r and f commands.
The command “set keymap=russian-jcukenwin” sets a bunch of these lmaps, which correspond to the regular Windows jcuken keyboard. The russian-jcukenwin is just the name of the mapping file. The one we need is already in the standard package.
After installing keymap, you can switch between Cyrillic and Latin by pressing Ctrl+^. This is what you want: commands and shortcuts do not suffer in any way when the russian layout is active. Hooray!
Resetting iminsert and imsearch is necessary so that the very first time you insert and enter a search pattern will start with Latin script. In fact, Ctrl+^ toggles these values between 0 and 1.
The last line ensures that the cursor changes color to bluish when the alternative layout is on. That is Cyrillic in our case. It’s very convenient.

Letter E

Suggestions not to be clever and type with an “e” or add words with an “e” to the addition dictionary as you go along didn’t appeal to me either. I needed another solution and it was under my feet!
setlocal spelllang=ru_yo, en_us

instead of the much publicized
:setlocal spelllang=ru_ru, en_us

asks Vim to use a dictionary with words with an “e” in it. And this is exactly what is needed. After this command ]s and [s no longer stumble over every “e”.
That’s it, now we don’t need the other editors. Thank you all. I hope it proves useful.

You may also like