I was wondering if anyone has ever looked at a way to switch back to normal mode automatically after inaction? In Vim, there are several methods to do that, such as:



The following function and idle timer will force evil back into normal state in all buffers after an idle delay of 30 seconds (which you can adjust as you like):

(defun evil-normalize-all-buffers ()
  "Force a drop to normal state."
  (unless (eq evil-state 'normal)
    (dolist (buffer (buffer-list))
      (set-buffer buffer)
      (unless (or (minibufferp)
                  (eq evil-state 'emacs))
    (message "Dropped back to normal state in all buffers")))

(defvar evil-normal-timer
  (run-with-idle-timer 30 t #'evil-normalize-all-buffers)
  "Drop back to normal state after idle for 30 seconds.")
  • perfect! this works well – zeltak Jul 12 '16 at 14:12
  • @Dan this worked well for me too, but I have two questions: 1. Doesn't the unless (eq evil-state 'normal) ... mean the "for loop" over buffers will be done if the current buffer is not in normal state? How would one modify this logic so that the for loop was done periodically regardless of the current buffer state, and all non-normal buffers were dropped into normal state? 2. How would I do the above so that only the buffers in insert state were reverted to normal state? Thanks in advance for any answers/pointers you can give me! – Edward Grefenstette Apr 28 at 14:49

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.