2020-02-21 14:50
People who use CJK or other non-Latin input methods can relate how pain it is to toggle input methods between insert and normal mode in (Neo)Vim. The first time I came across this problem several years ago, VimIM was the tool I found. But I always had problems with getting expected candidates or setting up on a new machine. I read the manual but it didn't change anything. (Yea, I must be dumb.) Also, the switching performance of VimIM was poor, and I'm not sure about the reason - my potato laptop, or the plugin itself. For a while, I use other editors instead of Vim to do my "CJK" job.
But finally I have had enough of it, because I always accidentally typed in "h", "j", "k", "l". A new search was started again. Tools like vim-barbaric and vim-xkbswitch, they don't have support for Windows OS or require the user to read the manual for an hour and to configure for another.
I'm probably wrong about them, and actually, I just want to write some code. So here is "neuims", neur1n's input method switcher.
Currently this plugin is only tested on Windows 7 and 10. And since commit fe2abf1, Python dependencies were removed and a binary written in C++ is used instead. The binary is static-linked, so it should work even there are no VC++ redistributables installed in your system.
Currently this plugin is only test on Ubuntu 16.04, and it is limited to
IBus. The ibus engine [ENGINE_NAME]
command is called to
switched the input method.
Put
Plug 'neur1n/neuims'
into your configuration file. But using the on-demand loading feature of vim-plug is recommended:
Plug 'neur1n/neuims', {'on': 'IMSToggle'}
This plugin needs to be manually enabled before being used to switch input methods. There are two ways to enable:
:IMSToggle
neuims#Toggle()
, or using a key
mapping, e.g.:
nnoremap <silent> <leader>it :call neuims#Toggle()<CR>
While in enabled status (can be checked with
:echo g:neuims.status
), use :IMSToggle
or press
<leader>it
again.
Usually, the switching is automatically controlled by the
InsertEnter
and InsertLeave
event. However, one
may call the function neuims#Switch(0)
to switch manually,
or using a key mapping, e.g.:
nnoremap <silent> <leader>is :call neuims#Switch()<CR>
There are default configurations in the source code:
let s:win = { \ 'im': 'US Keyboard', \ 'status': 0, \ 'keyboards': { \ 'US Keyboard': 0x0409, \ 'Microsoft Pinyin': 0x0804, \ }, \ } let s:ibus = { \ 'im': 'English (US)', \ 'status': 0, \ 'keyboards': { \ 'English (US)': 'xkb:us::eng', \ 'Pinyin': 'pinyin', \ }, \ }
This should work well with Windows's (7/10) and Ubuntu's (16.04) built-in input methods. Let's break it down:
For example, if one uses RIME (IBus based) in Ubuntu, the configuration may be:
let g:neuims = { \ 'im': 'English (US)', \ 'status': 0, \ 'keyboards': { \ 'English (US)': 'xkb:us::eng', \ 'Rime': 'rime', \ }, \ }