Close every buffer except the current one.
:bufdo bd closes everything including the buffer you're on, and doesn't
protect unsaved changes. :BufOnly keeps the current buffer, skips
unlisted buffers (help windows, quickfix, etc.), and by default skips
buffers with unsaved changes rather than silently discarding work.
With lazy.nvim:
{ "Hinikaa/bufonly.nvim" }With packer.nvim:
use "Hinikaa/bufonly.nvim"No setup() call needed -- the :BufOnly command registers itself.
:BufOnly " closes every other listed buffer, skipping ones with unsaved changes
:BufOnly! " force: also closes buffers with unsaved changes, discarding them
- The buffer-selection logic (
buffers_to_close) is pure and separated from thevim.apicalls, so it's tested both offline (lua5.1 test.lua) and against a real headless Neovim instance driving the actual:BufOnlycommand.
MIT, see LICENSE.