Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to change the name of a buffer in vim?

Specifically, I'm using Conque Shell to open shells in vim (each shell is in a buffer) and with multiple shells, I see:

10: bash - 1
11: bash - 2

in my buffer list. I would like to rename these buffers with more meaningful names (e.g., "mercurial" instead of "bash - 2"). Is it possible?

share|improve this question
up vote 21 down vote accepted

You can use :file newname to change the buffer name.

From :help :file_f:

Sets the current file name to {name}. The optional ! avoids truncating the message, as with :file.
If the buffer did have a name, that name becomes the alternate-file name. An unlisted buffer is created to hold the old name.

share|improve this answer
3  
Thank you. But, to me, it was surprising because I could not find that command using various google searches. – Barthelemy Nov 13 '10 at 10:59
1  
its important to note that this basically changes the file's save path. I was hoping for something like screen's naming of windows but it doesnt work like that – Jonny Leeds Mar 19 '15 at 11:03

Rename the current buffer with :file <new-name> (or :f <new-name>):

:f[ile][!] {name}

Sets the current file name to {name}. The optional ! avoids truncating the message, as with :file. If the buffer did have a name, that name becomes the alternate-file name. An unlisted buffer is created to hold the old name.

share|improve this answer

If the buffer already has a filename, :file will not change the filename and will only change the alternate filename. You'll need to clear the name of the buffer with :0f[ile] to be able to put one.

:e foo

:0f
:file bar
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.