Vim Tips Wiki
No edit summary
 
m (Reverted edits by 202.134.14.137 (talk | block) to last version by 114.32.241.146)
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=1126
 
|id=1126
  +
|previous=1120
|title=Automatically set screen title
 
  +
|next=1127
|created=February 9, 2006 18:25
+
|created=February 9, 2006
 
|complexity=basic
 
|complexity=basic
|author=Michael Stilkerich <ms--AT--mike2k.de>
+
|author=Michael Stilkerich
 
|version=6.0
 
|version=6.0
 
|rating=30/9
 
|rating=30/9
  +
|category1=
|text=
 
  +
|category2=
Screen's title field can automatically be updated to the name of the currently opened file (or whatever you like).
 
 
}}
 
The screen's title can automatically be updated to the name of the currently opened file, or whatever you like.
   
Just add the following to your .vimrc
+
Just add the following to your vimrc:
   
  +
<pre>
 
let &titlestring = hostname() . "[vim(" . expand("%:t") . ")]"
 
if &term == "screen"
 
set t_ts=^[k
 
set t_fs=^[\
 
endif
 
if &term == "screen" || &term == "xterm"
 
set title
 
endif
  +
</pre>
   
 
To create ^[, which is escape, you need to enter CTRL+V <Esc>
   
 
This will make a title like hostname[vim(filename)], but that's only my personal preference. That way, you can easily keep track on which window in your screen you have which file opened.
let &amp;titlestring = hostname() . "[vim(" . expand("%:t") . ")]"
 
   
 
==Comments==
 
Just found this on a website. Using:
   
  +
<pre>
  +
autocmd BufEnter * let &titlestring = hostname() . "[vim(" . expand("%:t") . ")]"
  +
</pre>
   
 
instead of statically setting titlestring even updates the title when switching buffers/opening other files in the same vim session.
if &amp;term == "screen"
 
   
set t_ts=^[k
 
 
set t_fs=^[\
 
 
endif
 
 
 
 
if &amp;term == "screen" || &amp;term == "xterm"
 
 
set title
 
 
endif
 
 
 
 
This will make a title like hostname[vim(filename)], but that's only my personal preference. That way, you can
 
 
easily keep track on which window in your screen you have which file opened.
 
}}
 
 
== Comments ==
 
Forgot to mention that to create ^[, which is escape, you need to enter
 
CTRL+V &lt;ESC&gt;
 
 
took me quite a while to figure this out ;-)
 
 
Michael Stilkerich &lt;ms--AT--mike2k.de&gt;
 
, February 9, 2006 18:26
 
 
----
 
----
 
I use:
Oh and just found this on a website:
 
   
  +
<pre>
Using
 
autocmd BufEnter * let &amp;titlestring = hostname() . "[vim(" . expand("%:t") . ")]"
+
set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:p:h\")})%)%(\ %a%)\ -\ %{v:servername}
  +
</pre>
   
 
By placing the expand expression inside a %{} pair, it is reevaluated automatically and doesn't require an autocommand around it.
instead of statically setting titlestring even updates the title when switching buffers/opening
 
other files in the same vim session.
 
   
Michael Stilkerich &lt;ms--AT--mike2k.de&gt;
 
, February 9, 2006 18:30
 
 
----
 
----
 
I tried it, and after editing a mail within mutt, the screen title keeps saying 'Thanks for flying Vim' instead of being reset to 'mutt'. Any ideas to fix this?
Hmm..
 
   
I use:
 
   
set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:p:h\")})%)%(\ %a%)\ -\ %{v:servername}
 
 
By placing the expand expression inside a %{} pair, it is reevaluated automatically and doesn't require an autocommand around it.
 
 
salmanhalim--AT--hotmail.com
 
, February 9, 2006 19:16
 
 
----
 
----
Hmm... I tried it, and after editing a mail within mutt, the screen title keeps saying 'Thanks for flying Vim' instead of being reset to 'mutt'. Any ideas to fix this?
 
   
  +
I use this to avoid "Thanks for flying Vim"
ronald--AT--schatenseite.de
 
  +
<pre>
, February 10, 2006 2:46
 
  +
set t_ts=^[k
  +
set t_fs=^[\
  +
auto BufEnter * :set title | let &titlestring = 'v:' . expand('%')
  +
auto VimLeave * :set t_ts=^[k^[\
  +
</pre>
 
----
 
----
Oh this is really a problem with all apps that fork off vim :-(
+
Oh this is really a problem with all apps that fork off Vim. You can hack around this in mutt using
You can hack around this in mutt using
 
   
  +
<pre>
source "~/.mutt/editorrc.$TERM"
+
source "~/.mutt/editorrc.$TERM"
  +
</pre>
   
in your muttrc and create a config for each terminal type,
+
in your muttrc and create a config for each terminal type, e.g. editorrc.screen:
e.g.
 
editorrc.screen:
 
set editor="sh -c 'vim $0 &amp;&amp; echo -ne \"\\033kmutt\\033\\134\"' "
 
   
  +
<pre>
this will reset the title to mutt after leaving vim. The problem with this is that you need an extra file for each terminal type you use,
 
 
set editor="sh -c 'vim $0 && echo -ne \"\\033kmutt\\033\\134\"' "
lots of the probably containing only set editor=vim
 
  +
</pre>
I don't know if there's a possibility to have mutt ignore silently if a sourced file does not exist in which case you could set editor to
 
a default value and override it only for some special terminal types.
 
   
 
This will reset the title to mutt after leaving Vim. The problem with this is that you need an extra file for each terminal type you use, lots of the probably containing only set editor=vim
btw, since we left the vim scope now anyway, here's the rest of my title configuring stuff
 
   
 
I don't know if there's a possibility to have mutt ignore silently if a sourced file does not exist in which case you could set editor to a default value and override it only for some special terminal types.
my .bashrc contains
 
case $TERM in
 
xterm*|rxvt*)
 
PROMPT_COMMAND='echo -ne "\033]0;${USER}--AT--${HOSTNAME}[`basename ${PWD}`]\007"'
 
;;
 
screen*)
 
PROMPT_COMMAND='echo -ne "\033k\033\134\033k${HOSTNAME}[`basename ${PWD}`]\033\134"'
 
;;
 
*)
 
;;
 
esac
 
   
 
btw, since we left the Vim scope now anyway, here's the rest of my title configuring stuff
and my .screenrc contains
 
shelltitle '] |bash'
 
   
 
my .bashrc contains
This will have the shell display hostname[last component of directory] whenever no program is running and
 
  +
<pre>
enable screens heuristic to display the program name whenever a program is running.
 
 
case $TERM in
The fallback value bash is almost never displayed since it will be overriden by the shell prompt. For shells other than
 
 
xterm*|rxvt*)
bash you should be able to configure this in a similar way. (there are examples in the screen manual). The characters
 
 
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}[`basename ${PWD}`]\007"'
in shelltitle before the pipe sign need to fit the end of your shell prompt, which is "] " in my case.
 
 
;;
 
screen*)
 
PROMPT_COMMAND='echo -ne "\033k\033\134\033k${HOSTNAME}[`basename ${PWD}`]\033\134"'
 
;;
 
*)
 
;;
 
esac
  +
</pre>
   
 
and my .screenrc contains
Michael Stilkerich &lt;ms--AT--mike2k.de&gt;
 
  +
<pre>
, February 10, 2006 10:27
 
 
shelltitle '] |bash'
----
 
  +
</pre>
'Thanks for flying Vim' is still on my screen status. How can I get rid of it?
 
I just simply use bash to run vim, and I just close it.
 
   
 
This will have the shell display hostname[last component of directory] whenever no program is running and enable screens heuristic to display the program name whenever a program is running.
milan.berta--AT--matfyz.cz
 
, February 12, 2006 4:01
 
----
 
Actually, what I want is to save the current settings of the screen title and after closing vim to set it again to old one.Is it possible?
 
   
  +
The fallback value bash is almost never displayed since it will be overriden by the shell prompt. For shells other than bash you should be able to configure this in a similar way. (there are examples in the screen manual). The characters in shelltitle before the pipe sign need to fit the end of your shell prompt, which is "] " in my case.
milan.berta--AT--matfyz.cz
 
, February 12, 2006 4:03
 
----
 
Actually, what I want is to save the current settings of the screen title and after closing vim to set it again to old one.Is it possible?
 
   
milan.berta--AT--matfyz.cz
 
, February 12, 2006 4:04
 
 
----
 
----
<!-- parsed by vimtips.py in 0.476430 seconds-->
 

Revision as of 14:51, 8 September 2015

Tip 1126 Printable Monobook Previous Next

created February 9, 2006 · complexity basic · author Michael Stilkerich · version 6.0


The screen's title can automatically be updated to the name of the currently opened file, or whatever you like.

Just add the following to your vimrc:

let &titlestring = hostname() . "[vim(" . expand("%:t") . ")]"
if &term == "screen"
  set t_ts=^[k
  set t_fs=^[\
endif
if &term == "screen" || &term == "xterm"
  set title
endif

To create ^[, which is escape, you need to enter CTRL+V <Esc>

This will make a title like hostname[vim(filename)], but that's only my personal preference. That way, you can easily keep track on which window in your screen you have which file opened.

Comments

Just found this on a website. Using:

autocmd BufEnter * let &titlestring = hostname() . "[vim(" . expand("%:t") . ")]"

instead of statically setting titlestring even updates the title when switching buffers/opening other files in the same vim session.


I use:

set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:p:h\")})%)%(\ %a%)\ -\ %{v:servername}

By placing the expand expression inside a %{} pair, it is reevaluated automatically and doesn't require an autocommand around it.


I tried it, and after editing a mail within mutt, the screen title keeps saying 'Thanks for flying Vim' instead of being reset to 'mutt'. Any ideas to fix this?



I use this to avoid "Thanks for flying Vim"

        set t_ts=^[k
        set t_fs=^[\
        auto BufEnter * :set title | let &titlestring = 'v:' . expand('%')
        auto VimLeave * :set t_ts=^[k^[\

Oh this is really a problem with all apps that fork off Vim. You can hack around this in mutt using

source "~/.mutt/editorrc.$TERM"

in your muttrc and create a config for each terminal type, e.g. editorrc.screen:

set editor="sh -c 'vim $0 && echo -ne \"\\033kmutt\\033\\134\"' "

This will reset the title to mutt after leaving Vim. The problem with this is that you need an extra file for each terminal type you use, lots of the probably containing only set editor=vim

I don't know if there's a possibility to have mutt ignore silently if a sourced file does not exist in which case you could set editor to a default value and override it only for some special terminal types.

btw, since we left the Vim scope now anyway, here's the rest of my title configuring stuff

my .bashrc contains

case $TERM in
 xterm*|rxvt*)
 PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}[`basename ${PWD}`]\007"'
 ;;
 screen*)
 PROMPT_COMMAND='echo -ne "\033k\033\134\033k${HOSTNAME}[`basename ${PWD}`]\033\134"'
 ;;
 *)
 ;;
esac

and my .screenrc contains

shelltitle '] |bash'

This will have the shell display hostname[last component of directory] whenever no program is running and enable screens heuristic to display the program name whenever a program is running.

The fallback value bash is almost never displayed since it will be overriden by the shell prompt. For shells other than bash you should be able to configure this in a similar way. (there are examples in the screen manual). The characters in shelltitle before the pipe sign need to fit the end of your shell prompt, which is "] " in my case.