In my vimscript, I need to get a count of all buffers that are considered listed/listable (i.e. all buffers that do not have the unlisted, 'u', attribute).
What's the recommended way of deriving this value?
In my vimscript, I need to get a count of all buffers that are considered listed/listable (i.e. all buffers that do not have the unlisted, 'u', attribute).
What's the recommended way of deriving this value?
A simple solution is using
getbufinfo
.In your vimscript:
or test it with command:
You could use
bufnr()
to get the number of the last buffer, then create a list from 1 to that number and filter it removing the unlisted buffers, by using thebuflisted()
function as the test expression.I would do it by calling
buflisted()
on the range of numbers up to the largest buffer number given bybufnr("$")
. Something like this: