I'd like to know how many windows are open in the current tab page from a Vim function; in particular, it would be handy to know if a particular window is the last, eg from an autocmd, in a tab page. Any ideas?
I'm guessing you can do it all with the winnr() command.
winnr() by itself tells you the window number you are currently in. winnr('$') tells you the last window (or window count)
The following would return '1' if you were in the last window, and 0 otherwise:
echo winnr() == winnr('$')
Taking your example you could then do something like this to execute something only on the last window:
:autocmd WinEnter * if winnr() == winnr('$')|echo "Welcome to the last window"|endif
You could also do the following:
let window_counter = 0
windo let window_counter = window_counter + 1
echo window_counter
The :windo
command runs an ex command in each window of your current tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With