Vim Tips Wiki
(Move categories to tip template)
 
(One intermediate revision by one other user not shown)
Line 17: Line 17:
   
 
<pre>
 
<pre>
let &amp;titleold=getcwd()
+
let &titleold=getcwd()
 
</pre>
 
</pre>
   
Line 37: Line 37:
   
 
The title will now have the original directory, not some/where/else, which is what it should be.
 
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.
   
 
----
 
----
Line 42: Line 44:
   
 
<pre>
 
<pre>
if &amp;term != "builtin_gui"
+
if &term != "builtin_gui"
let &amp;titleold=substitute(system("uname"),'\(.*\)\n','%\1%','')
+
let &titleold=substitute(system("uname"),'\(.*\)\n','%\1%','')
 
set title
 
set title
 
endif
 
endif

Latest revision as of 16:43, 8 February 2012

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.

Comments[]

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
:q!

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
endif