Andy Ray
Andy Ray

Reputation: 32076

How to show number of splits in tab in tab label in vim?

In VIM I use tabs like a well adjusted human being. I have file names as the tab label and I'm used to glancing at the tabs to find a file I want to edit. However, if that file is in a split in the tab, and the focus is on the other split, I won't see the file and I'll get horribly confused.

Is there a way to show the number of splits in the tab title? I've gone through the options in :h stl (tab titles use statusline syntax) but I don't see anything for splits. It seems like you can pass in a function as well, but I've tried searching for "vim count splits" and found nothing.

Also if there is some plugin which will facilitate this, I'm all ears.

Upvotes: 2

Views: 926

Answers (3)

romainl
romainl

Reputation: 196781

Stopping using tabs like that could help.

What you really want to do is "switch to a specific buffer which is in some tab", not "switch to some tab that has a specific buffer".

You can achieve that using either of two methods.

  • In your ~/.vimrc, add this line:

    set switchbuf=useopen,usetab
    

    and use the following command to jump to the buffer you want, wherever it is, or split the current window if it is not displayed anywhere:

    :sb bufname
    
  • Use a plugin that provides "better" buffer navigation. I use CtrlP which jumps to the buffer wherever it is (works more or less like the command above by default), there are others.

If you insist on thinking in "tabs", you could try:

:tabs<CR>:xtabn

with x being the number of the tab where your buffer is. The command above could be made quicker with a mapping, of course.

Upvotes: 1

Ingo Karkat
Ingo Karkat

Reputation: 172688

The last window number is equal to the number of window splits: tabpagewinnr(v:lnum, '$'). There's an example in the help at :help setting-guitablabel.

Upvotes: 1

Naveed
Naveed

Reputation: 726

However, if that file is in a split in the tab, and the focus is on the other split, I won't see the file and I'll get horribly confused.

To mitigate that problem, I :set ls=2.

Upvotes: 0

Related Questions