18

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?

  • 1
    I 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 Feb 12 '14 at 19:28
14

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.