开发者

Display number of current buffer

开发者 https://www.devze.com 2023-02-22 06:11 出处:网络
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 statu

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号