The tabpagewinnr()
can be used for this; for example:
:echo gettabinfo()
[{'windows': [1000], 'variables': {}, 'tabnr': 1},
{'windows': [1002, 1001], 'variables': {}, 'tabnr': 2}]
:echo tabpagewinnr(1)
1
:echo tabpagewinnr(2)
1
In this case, the first window is active in both tabs; the "winnr" is scoped to a current tab and starts at 1, whereas the "window id" is global and starts at 1000. To transform a winnr to a windows ID you can use win_getid()
:
:echo tabpagewinnr(1)->win_getid(1)
1000
:echo tabpagewinnr(2)->win_getid(2)
1001
The argument for win_getid()
is the tabnr; by default it will look up the winnr in the current tab so you need to specify it again.
For example to print all tabnrs with the currently active window's buffer name:
for t in gettabinfo()
let w = tabpagewinnr(t.tabnr)->win_getid(t.tabnr)->getwininfo()[0]
echo printf('%-4d %s', t.tabnr, bufname(w.bufnr))
endfor
Which should print something like:
1 file
2 two