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

  |   Source

I need toggle on input method to input Chinese (or any other language) in Emacs. The default hot key is "C-\" which corresponds the command "toggle-input-method".

My problem is since I'm using evil-mode (a Vim simulation), I need switch evil state from "normal" to "insert" before toggling on input method.

That extra step is not necessary if you insert below code into ~/.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 strongly recommend the Chinese input method eim written in pure elisp.

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

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

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

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

Comments powered by Disqus