Friday, May 11, 2012

Re: same backup dir, files same name

On May 11, 10:59 am, Doug <douglass_da...@earthlink.net> wrote:
> Hi,
>
> I am using Windows 7, vim 7.3
>
> I am using the same backup directory for all of the files I edit.  I
> would like to make it so that if I edit two files with the same name
> in different directories, the backup filenames would be different.
>
> I found this on the web:
>
> " Prevent backups from overwriting each other. The naming is weird,
> " since I'm using the 'backupext' variable to append the path.
> " So the file '/home/docwhat/.vimrc' becomes '.vimrc%home%docwhat~'
> au BufWritePre * let &backupext = '@' . substitute(expand('%:p:h'),
> '/', '%', 'g') . '~'
>
> But when I add it to my _gvimrc, it has no effect. Everything else in
> in _gvimrc works.
>
> It still always just saves the backup file with a  ~ at the end of the
> filename.  How can I change it so that I'm editing two files with the
> same name in different directories, they will have different backup
> filenames.
>
> - Doug

Ok, I figured it out. I'm on windows, so I have to get rid of : and \

Here's one that works:
au BufWritePre * let &backupext
='@'.substitute(substitute(substitute(expand('%:p:h'), '/', '%', 'g'),
'\', '%', 'g'), ':', '', 'g').'~'

- Doug

--
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

No comments: