Number of windows in VIM

I would like to know how many windows are open on the current tab from the Vim function; in particular, it would be useful to find out if a particular window is the last, for example, using autocmd, on a bookmark. Any ideas?

+5
source share
2 answers

I assume that you can do all this with the winnr () command.

winnr () itself tells you the number of the window you are currently in. winnr ('$') tells you the last (bottom) window

The following would return "1" if you were in the bottom window, and 0 otherwise:

echo winnr() == winnr('$')

Taking your example, you could do something similar to do something only in the bottom window:

:autocmd WinEnter * if winnr() == winnr('$')|echo "Welcome to the bottom window"|endif

Caveat: , , , / .

+6

:

let window_counter = 0
windo let window_counter = window_counter + 1
echo window_counter

:windo ex .

+4

All Articles