it works great!
yea when I posted that I hadn't really thought through the vimrc
commands at the bottom, i just thought it would make the directories
automatically.
if !has_key(s:, 'origbdir')
let s:origbdir = &bdir
endif
function! s:ChangeBackupSettings()
let dir = $HOME . "/Shortcuts/Backups/" . strftime("%y%m%d")
let &backupext ='.' . strftime("%H%M%S") . '.bak'
if ! filewritable(dir)
call mkdir(dir, "p")
if filewritable(dir)
let &bdir = dir . ',' . s:origbdir
else
echoerr "Failed to create backup directory, leaving unchanged!"
endif
endif
endfunction
augroup BackupSettings
au!
autocmd BufWritePre * call s:ChangeBackupSettings()
augroup END
On Dec 19, 10:07 pm, Sven Guckes <guc...@guckes.net> wrote:
> * kennethadammiller <kennethadammil...@gmail.com> [2009-12-20 04:54]:
>
>
>
> > I'm a beginner and newbie to vim.
> > I was just going to ask about how to set up my vimrc to
> > backup files to a directory that is depended on the date
> > with a file extension that is dependent on the time.
> > This is the current contents of my vimrc.
>
> > set nocompatible autoindent ruler incsearch history=300 so=4
> > syntax enable
> > filetype on
> > set patchmode=.orig
> > set backup
> > let &backupdir="/home/adam/Shortcuts/Backups/" . strftime("%y%m%d")
> > let &backupext=strftime("%H%M%S") . ".bak"
>
> > I was guided to use :let &back... by some
> > good folks on the IRC channel...
> > whenever I try to do it, though, I get
> > "E510: Can't make backup file (use ! to override)"
>
> so.. you are creating a name for a *directory* -
> but where is the command that *creates* it, too?
> vim does not creates directories for you - sorry!
>
> > how do i get it to do what I want?
>
> i suppose you need to run a command that
> creates the directory before you use it:
>
> :!mkdir &backupdir
>
> i think you should have added the year+month+day
> as part of the filename rather than the directory:
>
> let &backupdir="/home/adam/Shortcuts/Backups/"
> let &backupext=strftime("%y-%m-%d.%H%M%S.bak")
>
> mind you: untested. just some ideas.
>
> Sven
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment