Created
September 13, 2015 05:18
-
-
Save wilfredjonathanjames/ad3cd0f7a0c30816337f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Rename2.vim - Rename a buffer within Vim and on disk | |
" | |
" Copyright July 2009 by Manni Heumann <vim at lxxi.org> | |
" | |
" based on Rename.vim | |
" Copyright June 2007 by Christian J. Robinson <[email protected]> | |
" | |
" Distributed under the terms of the Vim license. See ":help license". | |
" | |
" Usage: | |
" | |
" :Rename[!] {newname} | |
command! -nargs=* -complete=file -bang Rename :call Rename("<args>", "<bang>") | |
function! Rename(name, bang) | |
let l:curfile = expand("%:p") | |
let l:curfilepath = expand("%:p:h") | |
let l:newname = l:curfilepath . "/" . a:name | |
let v:errmsg = "" | |
silent! exe "saveas" . a:bang . " " . l:newname | |
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment