3

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?

2
  • 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? Commented Aug 24, 2018 at 12:40
  • not possible as far as i know with pure Vimscript. Might work using python Interface. Commented Aug 24, 2018 at 13:12

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

@Maëlan well noticed. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.