Problem
I think many of the Russian-speaking Vim users often encountered the problem that when switching to Vim from mail / Skype / browser they forgot to switch the layout. Further events develop as follows:
- You have no map of Russian characters - Vim beeps, you swear and switch the layout;
- You have a map of Russian characters - most likely it is a curve, commands are not executed, Vim beeps, you swear and change the layout.
Obviously, the map of Russian characters is not the way out.
Decision
The correct solution is to switch the layout to English by pressing the Russian character in normal mode and enter the key that has already been pressed.
Implementation
This is the behavior that I wanted to implement.
The script (
github ) was very simple and straightforward.
First we check to see if our scrap is already loaded.
if exists('g:loaded_rusmode') || &cp || version < 700 finish endif let g:loaded_rusmode = 1
Then we will create a function for switching the layout and entering the pressed symbol:
function ChangeLayout(key) call system('osascript -e "tell application \"System Events\" to key code 49 using command down"') if a:key ==? ':' execute("normal! \<esc>:") else execute("normal!" . a:key) endif endfunction
And then follows a long and tedious nmap:
nmap <silent> <unique> :call ChangeLayout('q')<CR> nmap <silent> <unique> :call ChangeLayout('w')<CR> nmap <silent> <unique> :call ChangeLayout('e')<CR> ... nmap <silent> <unique> :call ChangeLayout('M')<CR> nmap <silent> <unique> :call ChangeLayout('<')<CR> nmap <silent> <unique> :call ChangeLayout('>')<CR>
I use MacOS, so the solution was written only for this system. If dear Linux users like this approach, I’m really looking forward to pull requests on the
githaba , write it yourself
setxkbmap -layout us
There are no problems, but there is no possibility to test, unfortunately.