1 " Rename2.vim - Rename a buffer within Vim and on disk
3 " Copyright July 2009 by Manni Heumann <vim at lxxi.org>
6 " Copyright June 2007 by Christian J. Robinson <infynity@onewest.net>
8 " Distributed under the terms of the Vim license. See ":help license".
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
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
26 echoerr "Could not delete " . l:curfile