updated on Tue Jan 17 12:00:36 UTC 2012
[aur-mirror.git] / vim-rename2 / Rename2.vim
blob074979155cda497872f24441f20c9873abe13558
1 " Rename2.vim  -  Rename a buffer within Vim and on disk
3 " Copyright July 2009 by Manni Heumann <vim at lxxi.org>
5 " based on Rename.vim
6 " Copyright June 2007 by Christian J. Robinson <infynity@onewest.net>
8 " Distributed under the terms of the Vim license.  See ":help license".
10 " Usage:
12 " :Rename[!] {newname}
14 command! -nargs=* -complete=file -bang Rename :call Rename("<args>", "<bang>")
16 function! Rename(name, bang)
17     let l:curfile = expand("%:p")
18     let l:curfilepath = expand("%:p:h")
19     let l:newname = l:curfilepath . "/" . a:name
20     let v:errmsg = ""
21     silent! exe "saveas" . a:bang . " " . l:newname
22     if v:errmsg =~# '^$\|^E329'
23         if expand("%:p") !=# l:curfile && filewritable(expand("%:p"))
24             silent exe "bwipe! " . l:curfile
25             if delete(l:curfile)
26                 echoerr "Could not delete " . l:curfile
27             endif
28         endif
29     else
30         echoerr v:errmsg
31     endif
32 endfunction