Switch input method in evil-mode (在Evil中快速切换输入法)

  |   Source

I need input Chinese (or any other language) in Emacs. The default key binding is C-\ to toggle input method.

Since I'm using evil-mode (Vim simulation), I need switch evil state from normal to insert before switching input method.

The extra keybindings could be optimized by below code in ~/.emacs:

(defun evil-toggle-input-method ()
  "when toggle on input method, switch to evil-insert-state if possible.
when toggle off input method, switch to evil-normal-state if current state is evil-insert-state"
  (interactive)
  (if (not current-input-method)
      (if (not (string= evil-state "insert"))
          (evil-insert-state))
    (if (string= evil-state "insert")
        (evil-normal-state)))
  (toggle-input-method))

(global-set-key (kbd "C-\\") 'evil-toggle-input-method)

BTW, I recommend the Chinese input method pyim written in pure elisp.

Emacs中切换其自带输入法的快捷键是=C-\=,对应的命令是=M-x toggle-input-method=.

我遇到的问题是如果使用Evil(一种Vim模拟)则切换输入法不方便.我需要先切换evil-state至insert,然后才能切换输入法.

只要将以上代码贴入=~/.emacs=,则切换输入法可以更加高效:

顺便提一下,pyim是强烈推荐的中文输入法.

Comments powered by Disqus