Is there a way that I can automatically save the file when leaving insert state to go to normal state with ESC?

1 Answer 1

(add-hook 'evil-insert-state-exit-hook
          (lambda ()
            (call-interactively #'save-buffer)))

This will call the underlying command of C-x C-s. You can also call evil-write if you prefer the :w command behaviour

  • I tried adding this to my .emacs file, but it didn't seem to save when exited insert state with the ESC key. I'm still new to emacs so there could be something else that I am missing.
    – Phaino
    Jun 13, 2019 at 4:16
  • try it again now: I've edited my answer because I had made a wrong copy-paste Jun 14, 2019 at 13:13
  • Works great! Thank you!
    – Phaino
    Jun 15, 2019 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.