Sunday, August 31, 2014

Re: set backupdir=~/.vim/backup//

On Sunday, August 31, 2014 6:24:06 AM UTC+12, Kaleb Hornsby wrote:
> In my vimrc, I have setup backupdir to be `set backupdir=~/.cache/vim/backup//,/var/tmp//,/tmp//`. The double slash does not seem to be working for 'backupdir', but it does work for 'undodir' and 'directory'.
>
> Instead of seeing a file like `%home%user%foo%bar.txt~` in my ~/.cache/vim/backup directory, I am seeing simply bar.txt~. This can lead to conflicts.
>
> Is this a vim bug or oversight, or have I configured something incorrectly?

I think this is something like an accepted oversight, because you can use an autocommand to rename the backup file how you like. I use such to timestamp the backup file names, a sort of poor man's versioning system. (I keep resolving to change to a proper system like git or hg, where every save is committed to a repository, but have not got round to it.)

Maybe (tested minimally, er, once):

function! StampBackup()
let bup = globpath(&backupdir, expand('%:t') . &bex)
if bup != ""
let modified = substitute(bup, '/[^/]*$', '', '') . '/' .
\ substitute(expand('%:p'), "/", "%", 'g')
if rename(bup, modified)
echoerr "failed rename of backup " . bup . " to " . modified
endif
endif
endfunction

augroup StampBackup
au! BufWritePost,FileWritePost * call StampBackup()
augroup END

Regards, John Little

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: