Search code examples
emacsevil-mode

Emacs evil-mode how to change insert-state to emacs-state automatically


I don't like the insert-state, and so I want to replace it with emacs-state. But this setting does not work:

(add-hook 'evil-insert-state-entry-hook 'evil-emacs-state)

After press o or cw, I am still in insert-state.


Solution

  • Tell me how this works. It's a hack that basically replaces the function evil-insert-state with evil-emacs-state. The problem is figuring out how to exit emacs state with the escape key. For instance, this version works fine when I exit emacs state with the ESC key, but not when I try to do the same with C-[:

    ; redefine emacs state to intercept the escape key like insert-state does:
    (evil-define-state emacs
      "Emacs state that can be exited with the escape key."
      :tag " <EE> "
      :message "-- EMACS WITH ESCAPE --"
      :input-method t
      ;; :intercept-esc nil)
      )
    
    (defadvice evil-insert-state (around emacs-state-instead-of-insert-state activate)
      (evil-emacs-state))