Is there a way that I can automatically save the file when leaving insert state to go to normal state with ESC?
1 Answer
(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.– PhainoJun 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
-