DasOhmoff San
DasOhmoff San

Reputation: 975

Vim - check if buffer is open in multiple windows

Is there a way to check if a single buffer is open in multiple windows? For example if you open up a file and you use the :vsp command, you can split up the current file into 2 windows, both looking at the same buffer, basically one buffer in two windows.

Single buffer:

enter image description here

The same buffer on two windows:

enter image description here

Is there a way to detect if one buffer is open in multiple windows via vimscript?

Upvotes: 5

Views: 1263

Answers (1)

Peter Rincker
Peter Rincker

Reputation: 45177

You can use win_findbuf() function which will take a buffer number and return a list of Window-IDs.

:echo win_findbuf(bufnr('%'))

For more help see:

:h win_findbuf(
:h winid
:h bufnr()

Upvotes: 7

Related Questions