From 5032aca04f4d0bce092ade66fe914c34af357a5e Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 27 Dec 2013 15:32:50 -0200 Subject: Initial import --- vim.dot.link/plugin/Rename.vim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 vim.dot.link/plugin/Rename.vim (limited to 'vim.dot.link/plugin/Rename.vim') diff --git a/vim.dot.link/plugin/Rename.vim b/vim.dot.link/plugin/Rename.vim new file mode 100644 index 0000000..b56c516 --- /dev/null +++ b/vim.dot.link/plugin/Rename.vim @@ -0,0 +1,27 @@ +" Rename.vim - Rename a buffer within Vim and on the disk +" +" Copyright June 2007 by Christian J. Robinson +" +" Distributed under the terms of the Vim license. See ":help license". +" +" Usage: +" +" :Rename[!] {newname} + +command! -nargs=* -complete=file -bang Rename :call Rename("", "") + +function! Rename(name, bang) + let l:curfile = expand("%:p") + let v:errmsg = "" + silent! exe "saveas" . a:bang . " " . a:name + if v:errmsg =~# '^$\|^E329' + if expand("%:p") !=# l:curfile && filewritable(expand("%:p")) + silent exe "bwipe! " . l:curfile + if delete(l:curfile) + echoerr "Could not delete " . l:curfile + endif + endif + else + echoerr v:errmsg + endif +endfunction -- cgit v1.2.3