2

:ls shows my buffers and lists flags for each buffer, but doesn't list whether &diff is set.

Plugins like unite's buffer source just rely on :ls output.

Is there an easy way to list and manage which buffers are in diff mode (for those times when :diffget fails due to more than two buffers in diff mode).

Ideally, I'd like something like :Unite buffer that includes 'diff' for buffers with &l:diff. A unite source that showed which buffers have certain variables would be cool: :Unite var diff scrollbind that works like :Unite buffer but appends 'diff' or 'scrollbind' to files with those options enabled.

1
  • 1
    Just a reminder that both :diffput & :diffget take a [bufspec] which can be a buffer number or a unique partial filename. e.g. :diffput foo. See :h dp. Bonus tip: set diffopt+=hiddenoff which turns off 'diff' when a buffer is hidden. Commented Jul 31, 2018 at 22:04

1 Answer 1

3

Something like

:echo join(
\          filter(
\                 map(
\                     range(1, winnr('$')), 
\                     'getwinvar(v:val, "&diff") ? "window:".v:val."  buffer:".winbufnr(v:val)." -> ".bufname(winbufnr(v:val)) : ""'), 
\                 '!empty(v:val)'),
\           "\n")

will return you the information you're looking for.

First of all, &diff is a window-local option. This means you can fetch its value with getwinvar(winnr, '&diff'), on all windows with range(1, winnr('$')). From there, if true, you have the window number, you can extract the buffer number with winbufnr(winnr) and display the name of the associated buffer with bufname(bufnr).

The join + filter part helps to keep only what matters and print one result per line.

Your Answer

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

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