I would answer Keflavich, but I still canβt ...
I worked on a similar issue when I wanted to imitate the behavior of gvim -remote-tab-silent when opening files inside gvim. I found this WhatTab script of yours, but ran into problems when several windows are open on any given tab. If you split the windows inside the tabs, you will have more than one buffer returned by tabpagebuflist (), so your method of using the position of the buffer number in the list does not work. Here is my solution that takes this opportunity into account.
" Note: returns a list of tabnos where the buf is found or 0 for none. " tabnos start at 1, so 0 is always invalid function! WhichTabNo(bufNo) let tabNos = [] for tabNo in range(1, tabpagenr("$")) for bufInTab in tabpagebuflist(tabNo) if (bufInTab == a:bufNo) call add(tabNos, tabNo) endif endfor endfor let numBufsFound = len(tabNos) return (numBufsFound == 0) ? 0 : tabNos endfunction
I think that I can just return tabNos, which will be an empty list that will be evaluated as scalar 0, but I just recognized vimscript, and I'm still not comfortable with the features of its dynamic behavior when typing, so I leave it like this now.
source share