Friday, August 12, 2011

Re: vim swap files

On Aug 12, 9:49 am, Gary Johnson <garyj...@spocom.com> wrote:

> In the mean time, you may want to turn off the 'backup' option and
> create your own backups using a BufRead autocommand ...

Or use the BufWritePost event to rename the backup that has just been
created. I sometimes do that to put a time stamp in the backup file
name, so that all such backup files are kept indefinitely. (I've been
persuaded that that using a version control system, checking in on
every save, is a better way to do the same thing, but haven't got
around to it.) Maybe (minimally tested):

function! ProjBackup()
let bup = globpath(&backupdir, expand('%:t') . &bex)
if bup != ""
let this = expand('%:p:h')
if this =~? 'myFirstProject'
let add = 'uniqueNameForMyFirstPeojct'
elseif this =~? 'mySecondProject'
let add = 'uniqueNameForMySecondPeojct'
else
" use last directory
let add = substitute(this,'.*[/\\]','',"")
endif
let newname = substitute(bup,'[\\/]\ze[^\\/]\+$','&' . add,
'')
if rename(bup, newname)
echoerr "failed rename of backup " . bup . " to " .
newname
endif
endif
endfunction

augroup ProjBackup
au! BufWritePost * call ProjBackup()
augroup END

HTH, and regards, John

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