You can use bufnr() to get the number of the last buffer, then create a list from 1 to this number and filter it by deleting unregistered buffers using the buflisted() function as a test expression.
" All 'possible' buffers that may exist let b_all = range(1, bufnr('$')) " Unlisted ones let b_unl = filter(b_all, 'buflisted(v:val)') " Number of unlisted ones let b_num = len(b_unl) " Or... All at once let b_num = len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
source share