Vim’s file backup system just saved my proverbial @$$ but I have a question.
I have vim saving backups to ~/.vim/backups
To restore them I went to the directory and (sorted by date) copied the files I needed back to the necessary directories in my project folder. Easy enough, there were only 5 files. However, I’m surprised there’s no obvious way to find which directory each file came from. I tried using vim -r path/to/file but that seems to use the swap and not the backup file. Since in my case vim didn’t crash (I just mistakenly overwrote the files) there is no swap for these files.
So the main question is: What is the best way to restore vim backup files?
Side question: What happens in the .vim/backup/ directory when I have two same-name files from different paths (e.g. /path/one/file.html and /path/two/file.html)?
From what I can tell, Vim doesn’t save any information at all regarding the file’s original location.
Saving a backup of two same-name files could either overwrite the existing backup or use a different name, depending on what’s set in your .vimrc. The option ‘backup’ will overwrite an existing backup file, but ‘writebackup’ will re-name a new backup in order to avoid an overwrite.
Check out Vim’s documentation for more info – :help backup