In my vimrc I have:
set backupdir=~/.cache/vim/backup |call mkdir(&backupdir, 'p', 0o700)
set undodir=~/.cache/vim/undo |call mkdir(&undodir, 'p', 0o700)
This stores a backup file in ~/.cache/vim/backup
on every write, which is useful if I accidentally remove something, or remove something that I ended up wanting to have later anyway.
The problem is that the filename is just the "basename", that is, both ~/one/README.md
and ~/two/README.md
get written as ~/.cache/vim/backup/README.md
, overwriting any previous file.
This problem doesn't exist for undodir
, which stores it as two files, with the full pathname:
~/.vim/cache/undo/%home%martin%one%README.md
~/.vim/cache/undo/%home%martin%two%README.md
How can I keep a unique copy for every pathname, similar to what undodir
does by default?