I'm using Vim 7.3 on OS X Terminal version 2.6.1 (OS X version 10.11.2). If it's relevant, my version is compiled without X11.

When I open a file in Vim, the terminal title bar changes to show the file name, as expected. Quitting the file with :q clears the title bar, also expected. The problem comes when using CtrlZ to stop Vim temporarily. After doing so, the title bar reads "Thanks for flying Vim". Restarting the stopped Vim instance with %% causes the title bar to once again display the file name. Finally, quitting Vim with :q leaves the title bar showing the file name, instead of blank as it should be.

Here's an example to clarify. Each step lists the action, the title bar that is expected, and the title bar that actually results.

  1. New terminal window – "" – ""
  2. vim foo.txt – "foo.txt" – "foo.txt"
  3. :q – "" – ""
  4. vim foo.txt – "foo.txt" – "foo.txt"
  5. CtrlZ – "" – "Thanks for flying Vim"
  6. %% – "foo.txt" – "foo.txt"
  7. :q – "" – "foo.txt"

As you can see, there are discrepancies between what I expect and what actually happens at steps 5 and 7. 5 can be fixed, I've found, with :set titleold=, to clear the old title variable. However, step 7 continues to vex me, and is clearly related to stopping Vim using bash job control.

How do I get the title bar properly restored even after stopping and restarting Vim using bash job control?

3 Answers 3


This problem was rendered (mostly) moot several years ago when xterm introduced the titlestack feature.

Most terminal emulators copied the feature, after it was made a part of the xterm terminal description in ncurses:

# 2017-12-30
#       + add xterm+noalt, xterm+titlestack, xterm+alt1049, xterm+alt+title
#         blocks from xterm #331 -TD

The xterm+titlestack block modifies the sequences used to switch to/from full-screen mode to save/restore the title:

xterm+titlestack|xterm 251 feature,
        rmcup=\E[23;0;0t, smcup=\E[22;0;0t,


documents how to change xterm title bars on the fly. You could make a little bash script to execute the code and run it within the terminal or as a vim key-mapping, as appropriate. Presumably other terminals have similar functionality.


The help for 'titlestring' says:

When Vim was compiled with HAVE_X11 defined, the original title will be restored if possible, see |X11|.

As you don't have X11 Vim won't help you.

In Bash you could use the environment variable PROMPT_COMMAND. The command defined in this variable is executed before the prompt is displayed (see man bash).

PROMPT_COMMAND='printf "\033]0;$PWD\007"'

This would set the title to display the current working directory. You can use any other text instead of $PWD.

Before changing PROMPT_COMMAND you should check if it is currently set and maybe extend the current value.

Your Answer

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

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