I'm building a custom vimrc to improve my workflow, and I really liked the idea of setting a centralized directory to keep all backup, swap and undo files together, like this:
" === BACKUP SETTINGS ===
" turn backup ON
set backup
set backupdir=~/.vim/backup//
" === SWAP FILES ===
" turn swap files ON
set swapfile
set directory=~/.vim/swap//
" === UNDO FILES ===
" turn undofiles ON
set undofile
set undodir=~/.vim/undo//
The double trailing slash is supposed to result in a filename expansion, where the resulting backup/swap/undo filename will be the full path, with %
replacing every /
, something like %home%username%path%to%your%file.ext
.
Everything works perfectly for swap and undo files, but backups refuses to work, generating filenames in the format file.ext~
without the full path expansion, which means that when I edit two files with the same name, the backup of the first is lost (overwritten by the second).
Does anyone have a clue about this problem?
UPDATE: this bug is now fixed since Vim 8.1.0251.
It seems like the 'backupdir'
option doesn't support the translation of the full absolute path into a filename (using %
for path separators) like 'directory'
and 'undodir'
do. At least nothing is mentioned under :help 'backupdir'
.
Since this is inconsistent, and I see your use case, you should submit a request at the vim_dev mailing list. Actually, there is already such a patch in the (veeery long) patch queue (:help todo.txt
):
7 The 'directory' option supports changing path separators to "%" to make
file names unique, also support this for 'backupdir'. (Mikolaj Machowski)
Patch by Christian Brabandt, 2010 Oct 21.
Please kindly lobby on the vim_dev mailing list to have its priority raised!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With