* Christian Brabandt <cbli...@256bit.org> [100120 11:25]: > On Wed, January 20, 2010 7:47 am, John Magolske wrote: > > I'd like to list in the statusline the current buffer number and the > > total number of open buffers. For example, if there are nine buffers > > open and I'm viewing buffer number two, I'd like to see: > > > > ~/somefilename.txt [2/9] > > > > I see that %n will place the current buffer number, but there doesn't > > seem to be a corresponding statusline item for the total number of > > buffers. How would I go about placing this value in the statusline? > > :let &stl.=' [%n/'.bufnr('$').']'
I tried something like this in my vimrc: set statusline=%F\ [%{bufnr('$')}] But bufnr('$') only lists the highest existing buffer number, with smaller-numbered buffers possibly removed by bwipeout...and I don't want to include, for example, a buffer displaying a help page in the count. Searching around some more, I found this solution [1]: set rulerformat=%22(%{g:zbuflistcount};%M%n\ %=%l,%c%V\ %P%) autocmd BufAdd * let g:zbuflistcount += 1 autocmd BufDelete * let g:zbuflistcount -= 1 autocmd VimEnter * call UpdateZBufLC() function UpdateZBufLC() let lst = range(1, bufnr('$')) call filter(lst, 'buflisted(v:val)') let g:zbuflistcount = len(lst) endfunction Which seems to work fine. I decided against using the fractional count & just put the total number in the statusline. I find it pretty handy to be able to tell at a glance how many relevant buffers are open, then use one of the many available tools [2] for navigating between them (bufferlist.vim ended up working best for my needs). [1] buffer list count http://www.mail-archive.com/vim-...@vim.org/msg02765.html [2] http://vim.wikia.com/wiki/Easier_buffer_switching Regards, John -- John Magolske http://B79.net/contact -- You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php