Reputation: 93
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?
Upvotes: 3
Views: 1086
Reputation: 59287
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
Upvotes: 1