Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gf3
Created May 2, 2017 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gf3/e922533716b31529bf626774a41217be to your computer and use it in GitHub Desktop.
Save gf3/e922533716b31529bf626774a41217be to your computer and use it in GitHub Desktop.
Vim Rename
" Rename buffer (:Rename) {{{
function! s:RenameBuffer(name)
silent! execute 'saveas! ' . a:name
let l:old_buffer = bufnr("#")
let l:old_filename = expand("#:t")
let l:new_buffer = bufnr("%")
let l:new_filename = expand("%:t")
silent! execute '!rm ' . shellescape(expand("#"), 1)
silent! execute 'bd' l:old_buffer
echom 'Renamed `' . l:old_filename . '` to `' . l:new_filename . '`'
endfunction
command! -nargs=1 Rename call s:RenameBuffer(<f-args>)
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment