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 know getbufinfo() gives you the buffer name in a variable called 'name', so I tried something like this: setbufvar(buffer_number, 'name', 'new_name_value'), but it just creates a b:name variable. Is there a specific way to address the buffer name?J. Doe– J. Doe2018-08-24 12:40:59 +00:00Commented Aug 24, 2018 at 12:40
-
not possible as far as i know with pure Vimscript. Might work using python Interface.Christian Brabandt– Christian Brabandt2018-08-24 13:12:58 +00:00Commented Aug 24, 2018 at 13:12
Add a comment
|
1 Answer
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
1 Comment
sidyll
@Maëlan well noticed. Thanks.