Matt, You can speed up the calculations considerably if you keep several things in mind: - buffer numbers are never reused. - built-in vim functions are written in C and are very fast - although you can open many files at once (like vim *.cs), buffers are usually (always?) deleted one at a time.
Try this (lightly tested): autocmd BufDelete * let s:prev_count -= 1 set rulerformat=%60(%=%{GetBufCount()}%) let s:prev_last = 0 let s:prev_count = 0 function! GetBufCount() let last = bufnr('$') if last != s:prev_last " A buffer has been added, update the count let lst = range(s:prev_last+1, last) call filter(lst, 'buflisted(v:val)') let s:prev_count += len(lst) let s:prev_last = last endif return s:prev_count endfunction David >> I'm doing this with the following code: >> autocmd BufAdd * let g:zbuflistcount += 1 >> autocmd BufDelete * let g:zbuflistcount -= 1 >> >> The problem is I found this to be very unreliable in some circumstances, >> and I'm not sure why. > > One thing that I think could cause it, is problem/restriction of > nested autocommands. By default, nested autocommands are suppressed. > Thus if autocommand creates abufffer, then [nested] autotommands > will not be executed (unless plugin uses word 'nested' ). Ahh yes. Thanks for the insight. I noticed that BufAdd would not be fired sometimes when plugins would create new buffers from autocmds (like minibufexpl plugin). I will read about this 'nested' keyword of which you speak. > > I just use bufnr('$') in my statusline. Simple and fast approximation. > > Yakov > --Matt