📜 ⬆️ ⬇️

Vim and Cyrillic: a couple of tricks

image

Previously, to edit ordinary Russian texts, I used to put Vim aside and use the help of other editors. The reason for this was a couple of very unpleasant shoals:
  1. For each sneeze, you had to switch the layout a hundred times to correctly enter a couple of commands and go back. For example, replacing a typo in a newly written word poured into: switch → get to the letter, press r → switch → [desired letter] → switch → A → [write further]. Hell!
  2. The staff spell checker didn’t like the letter , and any word with her participation suggested replacing it with an analogue through . And I love it, it upset me.

And finally, I found a solution to both problems. I sit now and type this text in Vim. It is curious that both barriers cost by standard means, without additional plug-ins. Since there are more materials in English and on them based on more than native Russians, it was not easy for me to find this information. Therefore, I want to share it with those who are interested.

Switch Layouts


I have met many times with the proposal to remap Cyrillic characters into Latin letters like this:

map q
map w
map e
map r
map t
map y
" ... ..

I did not like this decision because it left several problems. For example, you can not remap the punctuation, so the colon and slash on the Russian layout in any case move to new places. Also in paste mode, you cannot use combinations like Ctrl + W or Ctrl + R. All this was annoying.
')
We need another solution and it was found! In .vimrc:

set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0
highlight lCursor guifg=NONE guibg=Cyan

Now clarification. In Vim there is such a thing as lmap. It sets the conversion for all cases when it comes to entering characters as part of the text, but not as part of a command. So lmap is taken into account when inserting, entering a search pattern, after the r and f commands.

The "set keymap = russian-jcukenwin" command sets up a bunch of such lmap that correspond to the usual Windows keyboard. russian-jcukenwin is just the name of the mapped file. We need one already in the standard package.

After installing the keymap, you can switch between Cyrillic and Latin by pressing Ctrl + ^. At the same time, what happened was achieved: the teams and shortcuts do not suffer in any way with the active Russian layout. Hooray!

Resetting iminsert and imsearch is necessary so that the very first time the insertion and entry of the search pattern starts from the Latin alphabet. In effect, Ctrl + ^ switches these values ​​between 0 and 1.

The last line changes the color of the cursor to blue when the alternative layout is enabled. That is Cyrillic in our case. Very comfortably.

Letter yo


Proposals not to be clever and type through "e" or add words through "e" to the dictionary of additions in the course of work, I also did not like. We needed a different solution and it was under our feet!

:setlocal spell spelllang=ru_yo,en_us

... instead of being promoted everywhere

:setlocal spell spelllang=ru_ru,en_us

... asks Vim to use a dictionary with words through "e". And this is exactly what you need. After this command] s and [s no longer stumble over every "e".

Everything, now other editors are not necessary. Thanks to all. Hope to be helpful.

Source: https://habr.com/ru/post/98393/


All Articles