]> ruderich.org/simon Gitweb - config/dotfiles.git/commitdiff
vimrc: Display highest buffer number in 'statusline'.
authorSimon Ruderich <simon@ruderich.org>
Fri, 2 Mar 2012 13:25:11 +0000 (14:25 +0100)
committerSimon Ruderich <simon@ruderich.org>
Fri, 2 Mar 2012 13:25:11 +0000 (14:25 +0100)
vimrc

diff --git a/vimrc b/vimrc
index 7bd931f28cdc657cfa6da4c0aaef3dc2c7c133ec..87724343ab8db6aabc870b759245d3bb8b61b9bc 100644 (file)
--- 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 "/<nr>" (e.g. "/05") where <nr>
+    " 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