Skip to content

Instantly share code, notes, and snippets.

@howl-anderson
Last active March 13, 2020 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save howl-anderson/16e1424809393f98df05295d7ebf94ee to your computer and use it in GitHub Desktop.
Save howl-anderson/16e1424809393f98df05295d7ebf94ee to your computer and use it in GitHub Desktop.
Automatically switch to English keyboard when leaving insert/replace mode in Evil of Spacemacs. And when you enter insert/replace mode again, switch to whatever input method you used last time. Especially useful when you are using other language (non-english) to write content.
(defun dotspacemacs/user-config ()
(setq shell-file-name "/bin/bash")
; set default var lang_source for ibus arg
(setq lang_source "xkb:us::eng")
; what we do when enter insert mode
(add-hook 'evil-insert-state-entry-hook
(lambda ()
(shell-command (concat "ibus engine " lang_source))))
; what we do when enter normal mode from insert mode: always change to US keyboard
(add-hook 'evil-insert-state-exit-hook
(lambda ()
(setq lang_source (shell-command-to-string "ibus engine"))
(shell-command "ibus engine xkb:us::eng")))
; what we do when enter replace mode
(add-hook 'evil-replace-state-entry-hook
(lambda ()
(shell-command (concat "ibus engine " lang_source))))
; what we do when enter normal mode from replace mode: always change to US keyboard
(add-hook 'evil-insert-state-exit-hook
(lambda ()
(setq lang_source (shell-command-to-string "ibus engine"))
(shell-command "ibus engine xkb:us::eng")
)
)
)
@howl-anderson
Copy link
Author

howl-anderson commented Jan 2, 2020

Adjust the code to your input method, see the manual of ibus command to see what's the id of you input method (in this example is rime and xkb:us::eng). Only support the ibus-based input methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment