Search code examples
vim

Retain undo history if file is edited outside of Vim


The Vim undofile is purged when the file is edited outside the editor.

How can I get it so I can revert the file to older versions even if it was edited outside of Vim? Is this possible?


Solution

  • You can use vim backup:

    set backup                   " enable backup file
    set backupdir=~/.vim/backups " backup directory
    

    then you can go and grab the last backup vim saved in case you want to revert after an external edit but this is not like undofile. From vim wiki:

    However, note that if a file is modified externally without Vim, Vim will not be able to read the undo history back when you start editing the file again and the undo tree information will be lost. There is no way to get it back.