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.
A buffer is an area of Vim's memory used to hold text read from a file. In addition, an empty buffer with no associated file can be created to allow the entry of text. The :e filename command can edit an existing file or a new file.
You can enter the buffer number you want to jump/edit and press the Ctrl-W ^ or Ctrl-W Ctrl-^ keys. This will open the specified buffer in a new window.
The vi editor allows you to copy text from your file into temporary buffers for use in other places in the file during your current vi work session. Each buffer acts like temporary memory, or, as some programs call it, a "clipboard" where you can temporarily store information.
I edit it, then I use ':w' to save it and ':bd' to close the buffer and move on to the next one. This ':w:bd' to save and close the buffer feels long to me, and I suspect there's a more Vim ninja way of doing it.
: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('%')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With