Vim Tips Wiki

Show a useful title on exit in an xterm

1,610pages on
this wiki

Redirected from VimTip718

Tip 718 Printable Monobook Previous Next

created May 14, 2004 · complexity basic · author Jason P · version 6.0

If you're like me, you go to all the trouble of setting up your shell to put useful information in your xterm title. But on quiting Vim, there is no longer any useful information in the xterm title-- only "Thanks for Flying Vim".

Adding this line to your vimrc will make Vim put the current working directory in the xterm title on exit.

let &titleold=getcwd()

Should be simple to extend to include other information as well.


If you have vim compiled with X support it can restore terminal title itself.

Warning: That will record the cwd where you started vim. If you changed directories in the interim, setting that title will be incorrect. To reproduce:

% vim
(Suspend using ^Z)
% cd some/where/else
% fg

The title will now have the original directory, not some/where/else, which is what it should be.

In addition, the string produced by getcwd() upon exit is static and will not update as you change directories.

To set title back to the OS type:

if &term != "builtin_gui"
  let &titleold=substitute(system("uname"),'\(.*\)\n','%\1%','')
  set title

Around Wikia's network

Random Wiki