The default undo behavior in Evil is too coarse-grained because it considers anything taking place between entering insert mode and leaving it as one edit operation. When you enter a whole paragraph of text during one insert and then execute undo, the whole paragraph is removed. In contrast to that, Vim starts a new undo unit whenever you move the cursor in insert mode by means other than entering text.

Evil has a customization variable that can be used to get a more fine-grained undo history:

(setq evil-want-fine-undo t)

With this setting, Evil starts a new undo unit when the cursor is moved in insert mode, just like Vim does. However, this setting also messes with how the replace operation is handled: if you replace a word using cw, you have to undo twice to restore the original word: once for removing the new word and once for reinserting the original word. This is inconsistent with Vim and doesn't make much sense because replace should be atomic.

The question: How can I configure Evil and undo-tree in order to get Vim's undo behavior?

  • File an issue here: bitbucket.org/lyro/evil/issues?status=new&status=open (Evil generally considers divergences from vim to be bugs).
    – shosti
    Nov 10 '14 at 19:41
  • @shosti, you are right but the existence of the customization variable suggests that they decided to make an exception to that rule in the present case. I'll file a bug anyway. Let's see what happens.
    – tmalsburg
    Nov 10 '14 at 19:49
  • I think the customization variable is actually to get more Emacs-like undo behavior (Emacs doesn't do atomic operations in the same way as vim).
    – shosti
    Nov 10 '14 at 20:13
  • Here's the new issue: bitbucket.org/lyro/evil/issue/444/…
    – tmalsburg
    Nov 11 '14 at 20:46

Since @shosti pointed out that Evil considers deviation from Vim behavior as bugs, I filed a bug and one of the authors of Evil added a new possible value for evil-want-fine-undo:

(setq evil-want-fine-undo 'fine)

With this setting, you get new undo units when moving the cursor in insert mode, but replace operations are undone in one step. As far as I can tell this is consistent with Vim. See here for details.

  • 2
    This solution is not anymore recommended because the 'fine setting has been deprecated.
    – tmalsburg
    Jul 31 '16 at 20:23

According to the variable description (see C-h v evil-want-fine-undo) the value fine is not supported any more due to inconsistent behaviour.

As I use undo to undo typos or the mentioned setting helped my allot.

(setq evil-want-fine-undo t) 

I had trouble undoing errors in org-table formula editing, since you don't have to leave the insert mode if you want to change to *Edit Forumlas* with C-'.

  • Thanks for the update. I requested that the issue on Bitbucket is reopened.
    – tmalsburg
    Jul 31 '16 at 20:23


(setq evil-want-fine-undo t) 

and also

(advice-add 'undo-auto--last-boundary-amalgamating-number
            :override #'ignore)

as suggested in this answer, gives very fine granularity, that is, undoing each character entered in insert mode one by one.

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.