From: Simon Ruderich Date: Fri, 2 Mar 2012 13:25:11 +0000 (+0100) Subject: vimrc: Display highest buffer number in 'statusline'. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=15c46ed109a9cdceee55fe1dcdc0b5b15bc5ab46;p=config%2Fdotfiles.git vimrc: Display highest buffer number in 'statusline'. --- diff --git a/vimrc b/vimrc index 7bd931f..8772434 100644 --- a/vimrc +++ b/vimrc @@ -202,9 +202,34 @@ if has('statusline') " Always display the status line even if there is only one window. set laststatus=2 + " If there's more than one buffer return "/" (e.g. "/05") where + " is the highest buffer number, otherwise return nothing. Used in + " 'statusline' to get an overview of available buffer numbers. + function! StatuslineBufferCount() + let l:bufnr = bufnr('$') + if l:bufnr > 1 + let l:result = '/' + if exists('*printf') + let l:result .= printf('%02d', l:bufnr) + else + " Older Vims don't have printf() (and no .= either). Emulate + " "%02d". + if l:bufnr < 10 + let l:result = l:result . '0' + endif + let l:result = l:result . l:bufnr + endif + return l:result + else + return '' + endif + endfunction + set statusline= " on the left - set statusline+=%02n: " buffer number + set statusline+=%02n " buffer number + set statusline+=%{StatuslineBufferCount()} " highest buffer number + set statusline+=: set statusline+=%f\ " path to current file in buffer set statusline+=%h " [help] if buffer is help file set statusline+=%w " [Preview] if buffer is preview buffer