10

I can get the vim title to display on my window by doing this:

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

But the tabs will say "Default".

From the commandline I can do this:

echo -ne "\e]1;hello world\a"

And that'll show "Hello World" in my tabs.

Is there a way to have vim write this stuff to my tab instead of title instead?

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
dd.
  • 922
  • 1
  • 7
  • 17

3 Answers3

12

This works for me:

" Set the title of the Terminal to the currently open file
function! SetTerminalTitle()
    let titleString = expand('%:t')
    if len(titleString) > 0
        let &titlestring = expand('%:t')
        " this is the format iTerm2 expects when setting the window title
        let args = "\033];".&titlestring."\007"
        let cmd = 'silent !echo -e "'.args.'"'
        execute cmd
        redraw!
    endif
endfunction

autocmd BufEnter * call SetTerminalTitle()

Source: https://gist.github.com/bignimbus/1da46a18416da4119778

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
mgaw
  • 121
  • 1
  • 3
4

I don't have iTerm, so I can't test this, but try adding this to your .vimrc:

set t_ts=^[]1;
set t_fs=^G

Type CTRL-V Escape for ^[ and CTRL-V CTRL-G for ^G.

Community
  • 1
  • 1
Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
  • Unfortunately, this isn't doing it for me. I have the nightly build of iTerm and vim 7.4.488. Setting these in my vimrc doesn't have an effect on the tab title. Using the echo -e command in the iTerm2 FAQs does work for me: http://iterm2.com/faq.html – Xander Dunn Dec 29 '14 at 23:04
  • Same result on latest stable iTerm2. – Xander Dunn Dec 29 '14 at 23:34
  • 1
    @thoughtadvances This is in addition to setting the title and titlestring: `set title titlestring=[%F]` –  Jun 20 '16 at 23:01
1

Just to piggy back on user2486953's comment above.

I was able to accomplish this with two super simple lines in my ~/.vimrc:

set title
set titlestring=%f

(Lower case 'f' gives me just the filename, whereas capital gives the full path too)

i.e. I didn't have to set anything with escape sequences like the accepted answer above. I am running gnome-terminal but I don't understand why iTerm2 would be any different for a VI setting.

brotherJ4mes
  • 159
  • 1
  • 5