Search code examples
vim

Undo many times in Vim?


Suppose state A in my document, I make change to B, C then D. Now I typed 'u', the state goes to C. I type 'u' again it goes back to D. (the second undo looks like redo to me).

In my understanding, undo means that I undo it once it will return to C, then undo again to it will return to B then undo again it will return to A.

Also, I know 'u3' can work here but in most cases I have no way to keep track of the number of state changes.

How can I achieve unlimited undo in Vim?


Solution

  • You have only 1 level of undo if you are in Vi compatible mode. You are missing out on a number of features by being in 'compatible' mode. Just create a ~/.vimrc file and you will automatically disable 'compatible' mode.

    What wonderful undo features do you get by using 'nocompatible'?

    • Unlimited undo
    • Persistent undo
    • Undo branches (like an undo tree)