Pursuing a vimscript function or expression that
count how many buffers been modified.
i.e., how many buffers :bm
could switch to,
given that option hidden
is set.
== Edit ==
In the hope of used in statusline
.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityFound it.
func! CountModifiedBuffer()
let mod = map(getbufinfo(), 'v:val.changed')
return len(filter(mod, 'v:val'))
endfunc
== Edit ==
I use %{IsBuffersModified()}
instead of builtin %m
inside my statusline
setting, which encode more info.
" [+] if only current modified, [+3] if 3 modified including current buffer.
" [3] if 3 modified and current not, "" if none modified.
func! IsBuffersModified()
let cnt = CountModifiedBuffer()
return cnt == 0 ? "" : ( &modified ? "[+". (cnt>1?cnt:"") ."]" : "[".cnt."]" )
endfunc
== Edit Edit ==
CountModifiedBuffer
could be one-liner.
return len(filter(getbufinfo(), 'v:val.changed == 1'))
getbufinfo
is deprecated. Use getbufvar
instead. Example: getbufvar(0, "&mod")
Mar 30, 2018 at 23:46
getbufinfo()
deprecation?
Jun 4, 2018 at 13:35
getbufinfo
to render the buffers in the tab bar, and either through vim telling me directly, or a source online that said to use getbufvar
, I found out that getbufinfo
has been deprecated. I'm trying to test getbufinfo
in vim right now and not only is it not working at all, but I can't find a single shred of documentation on it. :h getbufinfo
-> nothing; :h getbufvar
-> help page. So even if the source was wrong, getbufvar
is clearly more reliable.
Jun 4, 2018 at 21:51
:h getbufinfo()
. If I remember correctly it's quite recent. Much more recent than getbufvar()
. So indeed, getbufvar()
is to be preferred for portability reasons. But not because the other one has been deprecated. According to git blame, getbufinfo()
appears in v7.4.2204 and getbufvar()
in v7.0c13.
Jun 4, 2018 at 23:15