Skip to content

Instantly share code, notes, and snippets.

@gf3
Created May 2, 2017
Embed
What would you like to do?
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