Vim Recipes ‣ Display ‣ Changing the Window Title
You want to change the title of a Vim window to make it more descriptive.
Assign a value to the titlestring option, and set the title option. For example:
:set title titlestring=My\ Title
When working with multiple instances of Vim, it can be difficult to remember what task each window corresponds to. You can avoid this problem by customising each window's title. The window title can also function similarly to the status line, reminding the user about an important aspect of the current file.
The default window title contains the current filename, followed by a character indicating the state of this file, followed by the name of its directoryTo be precise, the directory name is followed by a hyphen then the value of &v:servername, if set, otherwise just VIM.. The state character is one of the following:
This is already quite a descriptive title, but we can customise it further using a format string, as described in the Changing the Status Line recipe. The Vim documentation (:help titlestring) gives the following example:
:auto BufEnter * let &titlestring = hostname() . "/" .
expand("%:p")
Here the window title is reset when the user enters a new buffer. It contains the hostname, a forward slash, then the full path of the current fileFor an explanation of the %:p syntax see the Filename Modifiers section of the Executing External Commands recipe..
Another example is to display the value of an environment variable in the window title along with the filename. For instance, Ruby on Rails developers could prefix the filename with the value of RAILS_ENV, which indicates whether the application is in development, production, staging, or testing mode:
let &titlestring=expand($RAILS_ENV) . ": " .
expand("%:t")
One last trick is to embed the value of an external command in the window title using the %{system('command')} syntax. This could be used to display the name of the current branch, if using a version control system, or indicate whether the project's unit tests are passing or failing.