开发者

Number of Windows in VIM

开发者 https://www.devze.com 2023-01-25 16:16 出处:网络
I\'d like to know how many windows ar开发者_Go百科e 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, i

I'd like to know how many windows ar开发者_Go百科e 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消