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 equ开发者_运维知识库ivalent) 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.
: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
"}
To get the answer without configuring anything:
:echo bufnr('%')
You need %n
listed in your statusline
setting. Try :help statusline
in vim.
set statusline=%!bufnr('%')
Also see :help status-line
精彩评论