Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retain undo history if file is edited outside of Vim

Tags:

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?

like image 394
Steven Lu Avatar asked Nov 02 '22 20:11

Steven Lu


1 Answers

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.

like image 86
perreal Avatar answered Nov 12 '22 16:11

perreal