Neovim for Beginners — Buffer
Managing buffers, windows, and tabs is what we do daily as part of coding using Neovim. Let’s go through how to efficiently manage buffers, with and without plugins.
We are going to
- Learn the basics of managing buffers and the related commands.
- Develop a Lua-based module to select and jump to a buffer quickly.
- Configure a Lua-based plugin to manage buffers.
This article is part of the Neovim for Beginners series.
The Neovim configuration files can be found in this repository.
The Basics
From Vim help (:h window
),
A buffer is a file loaded into memory for editing. The original file remains
unchanged until you write the buffer to the file.A window is a viewport onto a buffer. You can use multiple windows on one
buffer, or several windows on different buffers.A tab page is a collection of windows.
A buffer has a unique number and can have 3 states — active, hidden, and inactive.
- An active buffer means the buffer is displayed in a window, and the loaded file may or may not be modified.
- A hidden buffer is just like an active buffer, except that we cannot see it.
- An inactive buffer means the buffer is not displayed and does not contain anything.
When we try to quit Neovim while there is a hidden, modified buffer, we will
get an error message and Neovim will make that buffer the current buffer. We
can then decide to write this buffer (:wq
) or quit without writing (:q!
).
Some of the common buffer operations are described below. Refer to the help for the full documentation.
Display Buffer
The:buffers
or :ls
command shows all the buffers. When the !
is included the list will show unlisted buffers.
- In the screen below we can see
windows.txt
is an unlisted buffer with anu
indicator. The-
indicates it is not…