A simple Neovim plugin that automatically closes buffers when you leave them if they haven't been modified since opening.
- Automatically closes unmodified buffers when you switch away from them
Using lazy.nvim:
{
"iAverages/auto-buffer-close.nvim",
opts = {}
}The plugin can be configured with the following options:
require("auto-buffer-close").setup({
ignore_blank_lines = true, -- Whether to ignore blank lines when comparing buffer content
})Simply call the setup function in your Neovim configuration:
require("auto-buffer-close").setup()- When you enter a buffer for the first time, the plugin stores its content
- When you leave the buffer, it compares the current content with the stored content
- If the content is unchanged, the buffer is automatically closed
- Special buffers (terminals, help, etc.) and unnamed buffers are ignored
In VS Code, when you open a file from the file explorer or through quick open, it opens in "preview mode" - shown with an italic filename in the tab. If you navigate away without making any changes, the tab automatically closes to keep your workspace clean. This plugin brings similar behavior to Neovim by automatically closing unmodified buffers when you leave them. Mostly useful if you have a bufferline plugin to display open buffers.
This helps maintain a cleaner buffer list and reduces the mental overhead of managing dozens of open buffers that you only briefly viewed.