3

So, I found this useful answer about iterating buffers; but due to the tabpage-specific duality of windows in Vim, I failed at adapting it to my needs.

Thus: how can I construct a boolean expression, determining whether or not any (not just the current) window in the tabpage is in &diff-mode?

2 Answers 2

7

You can sum up the values of &diff for each window, and see if the total is > 0:

let any_diff = 0
windo let any_diff += &diff
echo any_diff . ' windows in diff mode'
if any_diff > 0 | do stuff | endif
5

I don't like using windo that could trigger events if done without any caution, and thus I prefer using programmatic ways instead.

For instance, we can obtain the window numbers of the windows in diff mode with

:echo filter(range(1, winnr('$')), 'getwinvar(v:val, "&diff") == 1')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.