Tip 24Making Undo Persist Between Sessions

The undo command is a lifesaver when you need to revert changes that didn’t work out. Typically, you can only undo changes that were made to a file during the current editing session. By enabling Vim’s ‘undofile’ option, you can make undo history persist between editing sessions.

Open the green-bottles.txt file from the source code that accompanies this book in Vim:

 10 green bottles hanging on the wall.

Use the <C-x> command to decrement the number at the start of the line. Now you can use u to undo the change and <C-r> to redo it. If you quit Vim and then reopen the same file, what do you expect to happen when you use the u command?

Your undo history is usually lost when you ...

Get Modern Vim now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.