Display number of current buffer

Daniel picture Daniel · Apr 5, 2011 · Viewed 9.5k times · Source

I have a simple requirement: I want to display the number of the buffer I'm currently editing. I don't want to type :buffers (or equivalent) but have this number show up in my status bar thingy along with the file name, current column information etc.

Is there any way to do this? Inbuilt help isn't very instructive on this point.

Answer

N 1.1 picture N 1.1 · Apr 5, 2011

:h statusline shows every bit of help required.

I have the following in my .vimrc

" Status Line {  
        set laststatus=2                             " always show statusbar  
        set statusline=  
        set statusline+=%-10.3n\                     " buffer number  
        set statusline+=%f\                          " filename   
        set statusline+=%h%m%r%w                     " status flags  
        set statusline+=\[%{strlen(&ft)?&ft:'none'}] " file type  
        set statusline+=%=                           " right align remainder  
        set statusline+=0x%-8B                       " character value  
        set statusline+=%-14(%l,%c%V%)               " line, character  
        set statusline+=%<%P                         " file position  
"}