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"
  (if (not current-input-method)
      (if (not (string= evil-state "insert"))
    (if (string= evil-state "insert")

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

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





Comments powered by Disqus