Vim: change label for specific tab

19

5

Say I have a bunch of tabs open in Vim, with a tabline looks something like this:

1 v/file1.py 2 t/file.py 1 t/file.py 1 o/otherfile.py

See how two tabs both say "t/file.py"? Those are different files, they just get turned into the same tab label.

In my workflow the tab titles are often ambiguous (yay for Chef naming everything "default.rb") or unhelpful ("I know one of these 8 tabs with 4 buffers each has that file I'm looking for...").

I'd like to rename the tabs to indicate what they logically represent:

1 homepage_view 2 tests 1 homepage_template 1 o/otherfile.py

I'm fine with tabs defaulting to a filename-based label, as long as I'm free to change it once the tab is created.

How can I do this in Vim?

spiffytech

Posted 2014-02-12T16:16:29.320

Reputation: 386

1I do not have time to experiment right now, but see :help setting-tabline (for vim in a terminal) or :help setting-guitablabel (for gvim). You could write a function that checks for a tab-local variable and returns either that or some default. Then, after opening a tab, :let t:mytablabel = 'homepage_template'. – benjifisher – 2014-02-12T19:28:18.363

Answers

15

There's a nice little plugin called Taboo that makes this easy. Just install it and then you can change the tab title with:

:TabooRename My Tab Title

You can look at the source code for that plugin if you're interested in writing your own solution.

Jonathan Potter

Posted 2014-02-12T16:16:29.320

Reputation: 271

Taboo is fantastic. TabooReset and TabooRename literally toggles two "modes" of the Tab-line ==> a named tab by Taboo, and an auto-named tab by Vim. This replicates the "named Windows" from Tmux perfectly. Better still, tabs named under Taboo can be restored using Startify (or under any other session-saving tools). – llinfeng – 2019-11-30T03:33:59.623

8

For gvim, see

:help 'guitablabel'
:help setting-guitablabel

Set the option to an expression that evaluates to t:mytablabel (a tab-local variable) if it exists, or else to an empty string (meaning to use the default):

:set guitablabel=%{exists('t:mytablabel')?t:mytablabel\ :''}

Maybe that is already too complicated, or maybe you want to get fancier. In that case, define a function:

function! GuiTabLabel()
  return exists('t:mytablabel') ? t:mytablabel : ''
endfunction
:set guitablabel=%{GuiTabLabel()}
:set go+=e

Then, in any tab where you want to override the default, do something like

:let t:mytablabel = 'homepage_template'

If you are using vim in a terminal, not gvim, then you have to set the 'tabline' option instead of 'guitablable'. This is a little more complicated, since you need a single expression that includes labels for all the open tabs. There is a complete example under

:help setting-tabline

benjifisher

Posted 2014-02-12T16:16:29.320

Reputation: 628