26

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.

N 1.1
  • 12,418
  • 6
  • 43
  • 61
Daniel
  • 263
  • 1
  • 3
  • 4

4 Answers4

38

: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  
"}  
N 1.1
  • 12,418
  • 6
  • 43
  • 61
34

To get the answer without configuring anything:

:echo bufnr('%')

Benjamin Atkin
  • 14,071
  • 7
  • 61
  • 60
4

You need %n listed in your statusline setting. Try :help statusline in vim.

zindel
  • 1,837
  • 11
  • 13
1
set statusline=%!bufnr('%')

Also see :help status-line

Stefan van den Akker
  • 6,661
  • 7
  • 48
  • 63
holygeek
  • 15,653
  • 1
  • 40
  • 50