Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why VIM backup filenames are not correct? 'backupdir' option not performing as expected

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.

like image 445
Victor Schröder Avatar asked Nov 04 '14 18:11

Victor Schröder


1 Answers

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!

like image 85
Ingo Karkat Avatar answered Sep 22 '22 08:09

Ingo Karkat