📜 ⬆️ ⬇️

Setup of support of Russian in GVim (windows)



Hi, Habr!

I want to share with the community the experience of completing Russian language support in GVim under Windows 7. GVim is a very powerful text editor, but in the current Windows implementation without fine tuning it looks like an ugly duckling compared to GVim under Linux or MacVim.
')
What will be in this article? Localization fix for Unicode in the Windows version of GVim, setting the switch keyboard layout, the inclusion of spell checking. It is assumed that you own the basics of working in Vim. On Habré already there is an article covering the topic of support for the Russian language, and although it still remains useful, but at the moment is a bit outdated.

In principle, the Russian language in the Windows interface version of GVim works out of the box, but there is a slight nuance: when Unicode is set, the editor does not display Cyrillic in messages and menus, so you have to switch GVim to English localization, or put up with these “krakozyabrami” in the menu and “nine” -s in the program's welcome. And this is in our time, when the overwhelming majority of programs and even standard notebook in Windows, by default, work with Unicode text! The situation is aggravated by the fact that there are simply no manuals on the network how to fix this problem. Like a beautiful girl, dancing beautiful dance and loud gas with each new pa.

Correct this misunderstanding!

Correction of the display of the Russian language in the GVim interface


First, let's fix the display of internal messages in Russian (text on the welcome screen, informational messages, error messages).


(The great and terrible out-of-the-box GVim when switching to UTF-8)

Create a vim.mo file from the utf-version of the Russian localization of the po-file (GNU gettext file format for multilingual support). In windows, I used the free Poedit program to create a mo file. We place the created mo-file in the $ VIMRUNTIME / lang / ru_RU.UTF-8 / LC_MESSAGES folder. If you do not have the ru_RU.UTF-8 and LC_MESSAGES folders (by default, they do not exist in the GVim windows), create them. If you are lazy to create and edit files, you can download mine: mo-file for version 7.4 , mo-file for version 7.3 , menu localization file . Now we have all the necessary files to support UTF-8.

Now we need to deal with the menu. A reasonable question arises: why the menu is not corrected with a correct mo-file? Everything is very simple - the menu in GVim is implemented with the help of plug-ins, so to fix the encoding, you need to fix the runtime file. Go to the $ VIMRUNTIME / lang folder, create a duplicate of the menu_ru_ru.vim file, rename it to menu_ru_ru.utf-8.vim and comment or delete the 20th line:

scriptencoding utf-8 


A careful reader will most likely notice when searching for a file that there is some similar file, namely menu_ru.utf-8.vim (without one “ru”). We don’t touch it, because GVim uses it by default (in Windows 7) and if we fix it, if we return to cp1251, we will get “krakozyabry”.

The case remains for the small: it is necessary to set the LANG environment variable in the system. There is nothing difficult in creating a new variable, but just in case I provide instructions. Go to the system settings Win + Break -> additional system parameters -> Advanced -> Environment variables -> Create ... Enter the variable name LANG, the value of ru_RU.UTF-8.
If for some reason you cannot create environment variables, then you can add several lines to _vimrc:

 "       lan mes ru_RU.UTF-8 "     source $VIMRUNTIME/delmenu.vim set langmenu=ru_RU.UTF-8 source $VIMRUNTIME/menu.vim 


If you haven't turned on Unicode yet, it's time to do it. Open _vimrc and add the line set encoding = utf-8. Now when you start GVIM with UTF-8 installed, all messages will be displayed in normal Russian.


(Great and terrible GVim after making corrections)

Setting the switch layout in GVim


Why do something with switching layouts and give up your favorite Ctrl + Shift / Alt + Shift? The answer is simple - it is not convenient.

A simple example: let us write something in Russian in GVim, first clicking Alt + Shift, and suddenly we saw an error at the beginning of the previous paragraph. In this case, we need to press "ESC" and "{" to go to the beginning of the last paragraph for corrections, but this will not work, since we have the Russian layout enabled and instead of the curly bracket we will send a hard sign to the editor. That is, after exiting the insert mode, we need to switch back to the English layout again in order for the standard editor commands to work. GVim provides its own layout switching mechanism to avoid this inconvenience. In order to enable it, add to the _vimrc lines:

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


After making changes by pressing Ctrl + ^, we will switch the layout, while in the input mode of the Russian language the cursor will turn blue. (For an explanation of what each of the teams is doing, refer to the article that was mentioned at the very beginning)


(Tuned GVim in Russian input mode)

Also, a great plugin recently appeared that makes it easier to work with several languages.

Setting up a spell checker in GVim


Spell checking is enabled using the command:

 :setlocal spell spelllang=ru_ru,en_us 


When you first start from the Internet, all the necessary dictionaries are loaded, after downloading, the spell check is immediately turned on.



Previously, for correct verification of words containing “”, it was necessary to additionally install the ru_yo dictionary, now one ru_ru is enough. But after connecting ru_yo, words in which “” was replaced with “e” will be underlined in blue.



Spell checking is disabled with the command:

 :setlocal spell spelllang= 


Voila! Now you can enjoy the full support of the Russian language in GVim.

I hope that the article is easy to understand and will be useful to someone.

PS Post a bug about the need to translate windows-version of GVim from default cp1251 to utf-8, while there were no comments; I think that in the upcoming Vim 7.4 UTF-8 will take its rightful place.

PPS If someone liked my illustration, you can pick up (cc-by-sa 3.0 license).

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


All Articles