How to map the Kana key on Japanese keyboards

166 views
Skip to first unread message

Horacio Sanson

unread,
Jan 17, 2014, 8:54:23 AM1/17/14
to vim...@googlegroups.com
Japanese keyboards have a Kana key that allows me to easily switch between Japanese and English input.

Is very common for me during insert mode to press the Kana key to input some Japanese text after which I press esc to go back to normal mode.


The problem is that after entering normal mode the input method is still in Japanese and it is totally useless in vim normal mode. It is impossible to input any command with the Japanese input and since I get no feedback it takes some seconds before I realize why everything I type seems to do nothing in vim.

I would like to make a mapping so when I exit insert mode (or enter normal mode) the input method is always reset back to English. Unfortunately I am unable to find how to map this key.

Bonus points if I can make remember the last input method used in insert mode and restore it when entering insert mode again.

Other, possibly better solution, is to find out how to change the input method via command line and make a autocmd that executes the command when entering normal mode. Unfortunately I still cannot find a way to manipulate the input method from the command line. BTW: I use Linux (Kubuntu) with ibus as input method manager.


thanks,

Yukihiro Nakadaira

unread,
Jan 18, 2014, 9:28:38 AM1/18/14
to vim...@googlegroups.com

If you are using GUI version of vim, you can use 'imactivatefunc' and
'imstatusfunc' option to control Input Method.

For ibus, you can try https://github.com/koron/imcsc-vim/tree/master/ibus-python.
This is a plugin to control ibus using these options.  This requires
if_python feature.  But unfortunately latest ibus removes some API
required by this plugin.  So perhaps it may not work in your PC.

To just inactivate Input Method, you can use InsertLeave event.  Open
Input Method settings dialog and set shortcut key to set off Input
Method.  Then, send the key in InsertLeave event.
For example, if shortcut key is ctrl-shift-j:
  :autocmd InsertLeave * call system('xvkbd -text "\[Control]J"')

--
Yukihiro Nakadaira - yukihiro....@gmail.com

Horacio Sanson

unread,
Jan 22, 2014, 4:51:30 AM1/22/14
to vim...@googlegroups.com
Thanks for your answer, I learned a lot about the imactivatekey option. Unfortunately I work mainly on terminal vim and all my attempts with this option failed.

At the end I investigated how to manipulate IBus via DBUS and wrote a vim plugin to do the dirty work. This plugin disables IM when leaving insert mode and re-enables it when entering insert mode:

https://github.com/hsanson/vim-im

This plugin currently works on my desktop: Ubuntu 12.04 with KDE4 using IBus with Anthy for Japanese input. I have no plans to test other configurations but pull requests are welcome.

Horacio
Reply all
Reply to author
Forward
0 new messages