10

I have a pretty nice screen rc file that shows me the open screen windows almost like tabs at the bottom of the terminal. Currently the windows are named according to my prompt which is not so useful. Is there a way to automatically name the windows based on the filename of an open vim session currently in the window? I think this would make a supreme multi window editor if it were possible.

2 Answers 2

5

Set the title option. This works out of the box for me in xterm and the like but not in screen. This tip works:

if &term == "screen"
  set t_ts="\ek"
  set t_fs="\e\\"
  set title
endif

A different approach is to write a preexec function in your shell that sets the window title to the command being run. Zsh supports preexec natively, and bash can do it too. Here's a zsh example.

2
  • Hi. That did not work for me but I think it is because of how my .screenrc file is setup. 1 termcapinfo xterm* ti@:te@ 2 hardstatus alwayslastline 3 hardstatus string '%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]%{= b C}[ %m/%d %c ]%{W}'
    – user4785
    Feb 16, 2011 at 16:24
  • @user4785: If your prompt can set the Screen window title, Vim should be able to do it as well. What is your prompt? Does my .vimrc snippet work without your .screenrc? Feb 16, 2011 at 20:34
1

I did itusing a bit of a hackier way: Using tcsh I put the following in my .cshrc

# escape sequence to set the screen title
alias stitle 'echo -n "^[k\!*^[\\"'
# shorthand to set the screen title to the hostname
alias H stitle `hostname -s`
# shorthand to set the screen title to the filename, launch vim, and then set it back
alias vis 'stitle \!* ; vim \!* ; H'

So long as you remember to use vis instead of vim when you want the title there it works.

I also added

set notitle

to my .vimrc to keep vim from setting the title of the window screen was running in.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .