by Alexey Radkov and Dmitry Hrabrov a.k.a. DeXPeriX
If you allege and abode in two or added languages you may apperceive how it’s arresting to consistently about-face keyboard layouts manually, because vim in command approach can accept alone English letters. So you charge consistently change keyboard blueprint into English if you charge accomplish some command and if you are autograph texts, for example, in Russian, German or Chinese at the aforementioned time.
Vim plugin XkbSwitch can be acclimated to calmly about-face accepted keyboard blueprint aback and alternating aback entering and abrogation Admit mode. Say you are accounting some certificate in Russian and accept to leave Admit mode: aback you columnist <Esc> your keyboard blueprint switches to US/English automatically. Aback you added access Admit approach already afresh the Russian keyboard blueprint will be automatically switched back!
XkbSwitch requires OS abased keyboard blueprint switcher. Currently it depends on xkb-switch for UNIX / X Server and xkb-switch-win for Windows. For Mac OS X you can try xkbswitch-macosx or Input Antecedent Switcher. In the closing case you will accept to put line
into your .vimrc settings.
Gnome 3 no best works accurately with xkb-switch, so accede switching to g3kb-switch if you are application this desktop environment. The plugin can be loaded with
Keyboard layouts are stored alone for anniversary buffer
Keyboard layouts are kept complete while abyssal amid windows or tabs afterwards abrogation Admit mode
Automatic loading of language-friendly Admit approach mappings duplicates. For example, aback Russian mappings accept loaded afresh if there was a mapping
a new mapping
will be loaded. Admit approach mappings duplicates accomplish it accessible to administer absolute maps in Admit approach afterwards switching accepted keyboard layout.
Fast and accessible architecture of custom syntax based keyboard blueprint switching rules in Admit mode
Before accession of the plugin the OS abased keyboard blueprint switcher charge be installed (see About). The plugin itself is installed by extracting of the administration in your vim runtime directory.
Basic agreement requires alone 1 band in your .vimrc:
Additionally aisle to the backend switcher library can be defined:
However commonly it is not all-important as far as the plugin is able to acquisition it automatically. To accredit Admit approach mappings duplicates user may appetite to add
Here Admit mappings duplicates for Russian winkeys blueprint will be generated whenever Admit approach is started. It is accessible to ascertain a account of adapted layouts, for example
but currently alone Russian winkeys blueprint adaptation map (‘ru’) is accurate out of the box. There are 2 agency how a user can accommodate added definitions of keyboard blueprint adaptation maps (or alter absolute absence ‘ru’ map):
Define capricious g:XkbSwitchIMappingsTr:
Create a book with blueprint adaptation maps and put its aisle into capricious g:XkbSwitchIMappingsTrData, for example:
File with maps charge chase this format:
Sample book xkbswitch.tr with actually this agreeable is alien with this plugin distribution. It is encoded in UTF-8 and it is important as far as its agreeable is apprehend application readfile()! If your area is not UTF-8 and you appetite to use this sample book afresh it seems that you will accept to re-encode it in your area accepted encoding
Be actual accurate with mapping duplicates! They won’t alter absolute Admit approach mappings but may ascertain added mappings that will change accustomed Admit approach user experience. For example, plugin echofunc defines Admit approach mappings for ‘(‘ and ‘)’, accordingly bold that in Deutsch adaptation map there could be ‘)’ to ‘=’ translation, we would get ‘=’ abstract in any keyboard blueprint (as far as echofunc treats ‘)’ in a actual specific way). That is why this adaptation is missing in archetype aloft and in book xkbswitch.tr content.
There are assorted examples of agnate issues. For instance Russian winkeys construe ‘.’ into ‘ю’ and aback you are alteration a C/C antecedent book with enabled omnicompletion plugin appearance ‘ю’ (which you can use in comments) will consistently be replaced by ‘.’. To abode these issues starting from adaptation 0.10 a new capricious g:XkbSwitchSkipIMappings was introduced. It defines which aboriginal Admit approach mappings should not be translated for specific filetypes. Add into your .vimrc lines
and now you will be able to book ‘ю’ in C and C antecedent files. In this archetype six Admit approach mappings were banned for adaptation in two filetypes: C and C . The aboriginal three accord to omnicompletion plugin and the aftermost three abode plugin c.vim. Why mappings duplicates starting from ‘/’ were added: Russian winkeys construe ‘/’ into ‘.’ and this makes vim delay for a while until the abutting appearance afterwards ‘.’ has been amid which makes omnicompletion plugin about unusable. If you appetite to skip specific Admit approach mappings for all filetypes afresh you can use ‘*’ as the filetype key in g:XkbSwitchSkipIMappings.
Beware: capricious g:XkbSwitchSkipIMappings is not parameterized by keyboard layouts but alone by filetypes.
Besides accustomed Admit approach mappings, annals admittance translations are additionally supported. For example, actuality in Admit approach and accepting Russian winkeys blueprint on, you can admit agreeable of annals ‘a’ aloof columnist <C-R>ф afterwards switching accepted keyboard layout. To attenuate adaptation of annals names in Admit approach put line
into your .vimrc.
XkbSwitch is clumsy to assumption keyboard blueprint aback application Accustomed approach commands r and f and analytic with / and ?. Fortunately it can abetment keymap in this by setting
provided keymap is set to some value, for example
Now aback you leave Admit mode, the keyboard blueprint is switched aback to the accepted Accustomed approach value, but ethics of iminsert and imsearch are set depending on the aftermost Admit approach keyboard layout: if it was according to the amount of b:keymap_name that is commonly authentic in keymap files afresh they are set to 1, contrarily to 0. If keymap names do not bout arrangement keyboard blueprint names afresh you can remap them application capricious g:XkbSwitchKeymapNames.
Here ru and uk are arrangement keyboard blueprint names admitting ru_keymap and uk_keymap are ethics of b:keymap_name.
When added than two keyboard layouts are acclimated it apparently makes faculty to set keymaps dynamically in runtime. XkbSwitch can do it for you! You alone charge to ascertain a new variable
and map g:XkbSwitchKeymapNames to keymap names instead of ethics of b:keymap_name. For example
Now keymap will automatically about-face to the aftermost keyboard blueprint aback you leave Admit mode.
To displace commands r and f to the accepted Accustomed approach keyboard blueprint artlessly about-face to it in Admit mode. To displace chase curve columnist Ctrl-^.
There is alone one botheration not apparent so far: the arrangement keyboard blueprint indicator aback in Accustomed approach and chase curve will appearance the accepted Accustomed approach layout. We charge some adumbration that iminsert is alive and to what accent it points, it additionally would appearance what blueprint will be switched to aback we access Admit approach again. Actual acceptable feature, is not?
I will appearance how to accomplish a keymap indicator for the old Powerline plugin, newer offsprings like airline charge not alter a lot.
into the arrangement anesthetized to Pl#Segment#Init() in book autoload/Powerline/Segments.vim afore the band with fileformat, line
into the account anesthetized to Pl#Theme#Buffer() in book autoload/Powerline/Themes/default.vim (or whatever affair you are using) afore the band with fileformat, and lines
somewhere into the account anesthetized to Pl#Colorscheme#Init() in book autoload/Powerline/Colorschemes/default.vim (or whatever Powerline colorscheme you are using). Afresh access command
, restart vim and now the indicator charge assignment (but it will alone appearance keymap names aback iminsert is set).
By absence aftermost Accustomed approach keyboard blueprint is adequate aback abrogation Admit mode, but you can specify to use accurate blueprint for that:
Also you can specify aboriginal Admit approach keyboard layout:
Or actual Admit approach keyboard blueprint application absorber capricious with the aforementioned name:
If b:XkbSwitchILayout is set to the abandoned amount afresh the keyboard blueprint is not afflicted aback entering Admit mode. Be acquainted that momental switching from-and-to Admit approach (e.g. with Admit approach command <C-O> and all types of selections) will about-face accepted keyboard blueprint to the amount of b:XkbSwitchILayout. If you appetite to use actual Admit approach keyboard blueprint by absence afresh put line
into your .vimrc (change us to adapted amount if needed).
It makes faculty to attenuate XkbSwitch for buffers with specific filetypes, for archetype assorted book arrangement or tag navigators. For example, to attenuate XkbSwitch for NerdTree add in your .vimrc line
By absence (e.g. aback g:XkbSwitchSkipFt is not authentic in .vimrc) afterward filetypes are skipped: tagbar, gundo, nerdtree and fuf (FuzzyFinder).
You can accredit XkbSwitch in runtime (e.g. aback g:XkbSwitchEnabled is not set in your .vimrc) by arising command
This command will account accepted settings of g:XkbSwitchIMappings etc. Be acquainted that there is no way to attenuate XkbSwitch afterwards it has been enabled.
Imagine that you are alteration a simple concordance with 2 columns belted by vertical bars. In the aboriginal cavalcade you are autograph bottomward a German chat and in the additional cavalcade – its Russian translation. For example:
You appetite the keyboard blueprint to be automatically switched to the agnate accent aback you are affective amid the columns in Admit mode. It is feasible! Aback you alpha alteration about-face layouts in the both columns manually aloof once: afterwards that XkbSwitch will apprentice how to about-face them further. It will restore layouts afterwards abrogation Admit approach and entering it already again.
In this area it will be apparent how to accomplish this. Aboriginal of all there should abide belief aloft which XkbSwitch will adjudge aback it charge about-face layouts. The simplest belief are syntactic rules. So the agreeable of the columns charge be syntactically distinguishable. It agency that we charge a book with syntax rules and some new filetype defined, say mdict. For the account of artlessness let it be not an actually new filetype but rather a bracket of an absolute one, for archetype vimwiki. Afresh we should actualize a new book after/syntax/vimwiki.vim:
Here the syntactic belief accept been defined: agreeable of the aboriginal cavalcade will accept syntax id mdictOriginal and agreeable of the additional cavalcade – mdictTranslated.
In .vimrc afterward curve charge be added:
Function MdictCheckLang() does all the custom blueprint switching and can be admired as a plugin to the XkbSwitch. The aboriginal autocommand states that if book has addendum .mdict afresh its filetype charge be vimwiki and turns on XkbSwitch. The abutting two autocommands are another and alone accomplish alteration mdict files added comfortable. The aftermost autocommand (for CursorMovedI events) calls MdictCheckLang() aback cursor moves into adapted columns in Admit mode. The abutting definition
registers an InsertEnter autocommand in augroup XkbSwitch. If we had instead authentic an InsertEnter autocommand actuality afresh the command would accept been put afore the accepted InsertEnter autocommand in augroup XkbSwitch. Application capricious g:XkbSwitchPostIEnterAuto ensures that the new command will run afterwards the accepted InsertEnter autocommand. The additional aspect in an account central g:XkbSwitchPostIEnterAuto can be 0 or 1. If it is 1 afresh XkbSwitch won’t about-face blueprint itself aback entering Admit mode. In our case it should be 0 because MdictCheckLang() requires basal switching keyboard blueprint from XkbSwitch aback entering Admit mode.
Starting from adaptation 0.9 a all-encompassing abettor for architecture custom syntax based keyboard blueprint switching rules was implemented central the plugin code. Now architecture syntax rules is as simple as defining capricious g:XkbSwitchSyntaxRules in .vimrc. For example
registers syntax rules for files with addendum .mdict (the aboriginal aspect in g:XkbSwitchSyntaxRules: it replaces our old definitions of g:mdict_synroles, MdictCheckLang(), autocmd CursorMovedI and g:XkbSwitchPostIEnterAuto) and comments rules for C and C files (the additional aspect in g:XkbSwitchSyntaxRules). The comments rules ascertain that comments areas may accept their own keyboard layouts in Admit approach and aback cursor enters or leaves them the agnate layouts charge be restored. It may be advantageous if a user wants to accomplish comments in a accent that uses not accepted keyboard blueprint afterwards switching layouts aback and forth. Apprehension that the additional aphorism lists syntax groups in aspect inout admitting the aboriginal aphorism uses aspect in. The aberration is that in the case of the comments aphorism we appetite to restore basal keyboard blueprint (i.e. blueprint for cipher areas) aback abrogation comments areas, but in the mdict aphorism we do not affliction about abrogation areas mdictOriginal and mdictTranslated and alone affliction about entering them.
Some characters from another keyboard layouts may abort to access or behave in aberrant agency for assertive filetypes. For archetype in Russian winkeys blueprint characters ‘б’, ‘ю’, ‘ж’ and ‘э’ may abort to access in C antecedent files. The acumen of that is blueprint adaptation maps authentic in capricious g:XkbSwitchIMappings. You may assignment this about by artlessly not ambience this variable, or bigger by allegorical characters from the capital keyboard blueprint whose adaptation should be skipped application capricious g:XkbSwitchSkipIMappings. See capacity in area Basal configuration.
There is a accepted affair aback vim-latex amalgamation is installed. In this case entering Russian symbols in Admit approach aback alteration tex files becomes impossible. The affair arises from clashing XkbSwitch Admit mappings duplicates with mappings authentic in vim-latex. To assignment this affair about you can attenuate XkbSwitch Admit approach mappings duplicates for filetype tex:
When abrogation Admit approach afterwards application an another keyboard blueprint (say Russian), there could be a time lag (of breadth 1 sec if the amount of timeoutlen was not altered) afore accounting commands in Accustomed approach gets aback to aftermath any effect. To cope with this issue, the amount of ttimeoutlen (notice the double-t in the alpha of its name!) charge be set to some baby value, say
Related to X Server only. Aback alteration files on a alien host via ssh the ssh -X advantage charge be supplied:
This advantage will accomplish ssh advanced X Server agreement letters amid the bounded host and the alien host appropriately authoritative it accessible to about-face the bounded host keyboard layouts.
Related to GTK based gvim only. In bald X terminals keycodes for <C-S> and <C-Ы> are the aforementioned which makes it accessible to leave sequences with ascendancy keys in Admit approach mappings duplicates as they are. But this is not the case in GTK based gvim. The affair is still investigated.
XkbSwitch supports switching via Select approach too. But there is a case aback switching from Select approach to Accustomed approach will abort to restore Accustomed approach keyboard layout. This will appear aback abrogation Select approach afterwards any appearance accepting been entered. The acumen is simple: vim does not accomplish contest that could be bent by autocommands aback switching from Select approach to Accustomed mode. A workaround could be: aback you are abrogation Select approach afterwards any appearance entered do it via Visual mode, e.g. access <C-G><Esc> instead artlessly <Esc>.
There is a affray with plugin EnhancedJumps aback bufhidden=delete. Aback jumping aback to the antecedent absorber an absurdity message
will raise. This is because both autocommand BufRead of this plugin and EnhancedJumps will use redir accompanying which is not permitted. Commonly there is actual little anticipation to appointment this because advantage bufhidden is abandoned by default. To assignment this about you can add line
in your .vimrc. However this may breach the actual aboriginal keyboard blueprint switching from Select approach in a aloof accessible absorber if there was no inserting yet.
If you use gh-commands (gh, gH and g_CTRL-H) for your own specific purposes afresh you’ll apparently appetite to attenuate mappings authentic for some or all of these commands in the plugin. For example
disables plugin mappings for two of them.
How To Write In Russian On English Keyboard – How To Write In Russian On English Keyboard
| Pleasant for you to the blog, in this particular moment I am going to teach you about keyword. And now, this is the primary picture: