Persistent undo functionality in vim

Tags: software, howtos

Published on
« Previous post: Some Thoughts on Giving a Good Talk … — Next post: Network sockets—an ordeal (starring … »

Sometimes, it is the small things that make my day. I recently discovered that recent versions of vim offer a persistent undo functionality. This means I can edit my files, close them, and still be able to undo changes when I open them the next time. How cool is that?

The activation could not be simpler. Just place the following in your .vimrc:

set undofile
set undodir=$HOME/.vim/undo

The file path in undodir should refer to an actual directory in your .vim directory, so it might need to be created first. Furthermore, you can use the variables undolevels and undoreload to specify how many changes can be undone at most and how many modified lines should be saved, respectively.

I love vim more and more every day.