UPD: This is the “historical” version of the topic. A new solution to the problem is
here .
The problem of Russian layout in Vim has been raised many times. One solution can be seen
here , but it makes you get used to the new hot key for switching layouts. There are also many solutions with calling the system utility to change the layout, but under Windows I did not find such a utility, so I had to implement it myself.
In fact, it turned out the console interface for WinAPI-functions. To install a new layout for a window, the program gets the class name of this window and the two-letter language code. If there is such a window and the corresponding language code is found, then the program sends the WM_INPUTLANGCHANGEREQUEST message to this window.
To create a link to the program with Vim, he relied on a post from the
Tech Details blog. For the switch to work in Windows, add the following lines to _vimrc:
')
fun! <SID>xkb_switch(mode) let cur_layout = system('dxlsw.exe -get VIM') if a:mode == 0 if cur_layout != 'en' call system('dxlsw.exe -set VIM en') endif let b:xkb_layout = cur_layout elseif a:mode == 1 if exists('b:xkb_layout') && b:xkb_layout != cur_layout call system('dxlsw.exe -set VIM '.b:xkb_layout) endif endif endfun if executable('dxlsw.exe') autocmd InsertEnter * call <SID>xkb_switch(1) autocmd InsertLeave * call <SID>xkb_switch(0) endif
Also, don't forget to put
dxlsw.exe (3.5 KB) somewhere in
% PATH , for example, in
C: \ Windows \ System32 . If someone needs, then there is a
64-bit version (5 KB).
The source code (6.8 KB) is available under the LGPL2 license.
Advantages: works, switches the layout only in the Vim window.
Disadvantages: when calling the system function from GVim, the cmd.exe window opens for a short period of time and the GVim window briefly loses focus.
UPD:On the advice of habrayuzer,
ivnik assembled a DLL version of the language switch. The cmd window does not appear, there are no brakes.
_vimrc changed to:
fun! <SID>lib_kb_switch(mode) let cur_layout = libcallnr('libdxlsw', 'dxGetLayout', 0) if a:mode == 0 if cur_layout != 1033 call libcallnr('libdxlsw', 'dxSetLayout', 1033) endif let b:lib_kb_layout = cur_layout elseif a:mode == 1 if exists('b:lib_kb_layout') && b:lib_kb_layout != cur_layout call libcallnr('libdxlsw', 'dxSetLayout', b:lib_kb_layout) endif endif endfun autocmd InsertEnter * call <SID>lib_kb_switch(1) autocmd InsertLeave * call <SID>lib_kb_switch(0)
Put the DLL file in the directory with the Gvim EXE file. If Vim's 64-bit build, then use the appropriate library.