Question

Sometimes I use vim to write non-US text, and when I wanna use any command in normal mode, I need to change layout to US. It's possible to do that automatically?

PS. I can do mapping like this, but in this case command looks like :ц instead :w - not pretty and typo-risk.

Update

I don't want to use keymap option, because I prefer switch languages by CapsLock. I've try to write autocmd for InsertLeave event, but failed...

Update 2

Probably anybody know, why the following not work?

function SetUsLayout()
  !setxkbmap us,ru
endfunction

autocmd InsertLeave * call SetUsLayout()
Était-ce utile?

La solution 2

Looks like, that cross-platform solution doesn't exist... So, under KDE I use the following:

function! SetUsLayout()
  silent !qdbus org.kde.keyboard /Layouts setLayout us > /dev/null
endfunction

autocmd InsertLeave * call SetUsLayout()

Autres conseils

:help langmap

is likely to provide all the info you need.

For me, using qdbus is the best option. I've made a simple but fragile plugin that works really well for me: https://github.com/ironhouzi/bikey-vim/tree/master/plugin

I call it fragile, since it doesn't have much robustness to it if anybody else wants to use it.

I mostly want English when I'm using Vim, with a few exceptions. When I want to write in my native language, I hit 'leader'-k and my airline status bar will show that I've switched language. When the language is not English, the script will ensure that every time I enter insert mode, my native language is set through qdbus. Every time I leave insert mode, the language is set back to English. It also supports individual settings between buffers. Even though this might not be the best way to do things, I thought I'd share it, in case someone else might get some use out of it.

In Ubuntu I use the following:

function! SetUsLayout()
  silent !qdbus org.gnome.SettingsDaemon.Keyboard /org/gnome/SettingsDaemon/Keyboard org.gnome.SettingsDaemon.Keyboard.SetInputSource 0 > /dev/null
endfunction

autocmd InsertLeave * call SetUsLayout()

or shorter

silent !gsettings set org.gnome.desktop.input-sources current 0  
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top