Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim get/set buffer name without entering buffer

Tags:

vim

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?

like image 377
J. Doe Avatar asked Apr 29 '26 11:04

J. Doe


1 Answers

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
like image 76
sidyll Avatar answered May 02 '26 10:05

sidyll