A Neovim plugin to vacuum up unused file buffers
Install the plugin with your preferred package manager:
return {
  {
    'ChuufMaster/buffer-vacuum',
    opts = {}
  },
}
Buffer-Vacuum comes with the following defaults:
{
    -- The maximum number of buffers to keep (excluding modified buffer)
    max_buffers = 6,
    -- Change to True if you want pinned buffers to count to the
    -- maximum number buffers
    count_pinned_buffers = false,
    -- Enable notifications every time a buffer is pinned or deleted
    -- Default FALSE
    enable_messages = false,
}
BufferVacuum exposes 4 commands to the user:
If you're using auto-session and want pinned buffers to persist across sessions, you need to add the following configuration to your auto-session setup:
require('auto-session').setup({
    save_extra_cmds = {
        function()
            local commands = {}
            for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
                if vim.b[bufnr].pinned == 1 then
                    local filename = vim.api.nvim_buf_get_name(bufnr)
                    if filename ~= "" then
                        -- Generate command to set buffer variable directly
                        local escaped_filename = vim.fn.escape(filename, "'\\")
                        table.insert(commands, "call setbufvar(bufnr('" .. escaped_filename .. "'), 'pinned', 1)")
                    end
                end
            end
            if vim.tbl_isempty(commands) then
                return nil
            end
            return commands
        end
    }
    -- your other auto-session options...
})
Without this configuration, pinned buffers will not be remembered when you restore a session.