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"
  (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 recommend the Chinese input method pyim written in pure elisp.

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




Comments powered by Disqus