You can change the name of a buffer with the 'file' command, but you have to enter the buffer first. How can I use the getbufvar/setbufvar or a similar function to get/change the name of a buffer by just providing a buffer number, without entering it? Is there a way at all?
I don't think there is a native way of changing a buffer name, but restoring the current buffer is not a complicated task:
function! Rename(buffer, name)
let current = bufnr("%")
execute a:buffer . 'bufdo file ' . fnameescape(a:name)
execute 'buffer ' . current
endfunction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With