Vi and Vim Asked by ravron on August 31, 2021
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.
vim foo.txt
– “foo.txt” – “foo.txt”:q
– “” – “”vim foo.txt
– “foo.txt” – “foo.txt”%%
– “foo.txt” – “foo.txt”: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?
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 "