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?