www-gem words

[Plugin] The buffer list: mini.buffer


Making the buffer list auto refresh on deletion

#(Neo)vim #(Neo)vim-Plugins

If you use Neovim, chances are you’ve run into mini.nvim . It’s a collection of 45+ small, independent, lightweight tools that do one thing exceptionally well. In this post, I’d like to focus on mini.pick and how it can be used to show the buffer list.

Like other mini modules it’s awesome, but I was missing one thing: the ability to refrsh the buffer list on deletion.

The Context

Picture the scene. You’re deep in your workflow, hammering away at a config file, and you pull up your buffer picker using mini.pick mapped to a handy key combination. You’re browsing through a cluttered list of open files, and you decide to wipe out an old, unneeded buffer on the fly.

You trigger the deletion, but there’s a slight annoyance: the picker doesn’t dynamically update to reflect that the buffer is actually gone.

The good news it that this is not an issue for Neovim users as we know the ultimate superpower: if something is missing, you can implement it yourself :)

The Solution

To fix this, I came up with few lines of code to call a custom buffer removal function that does three things:

  1. Grabs the currently selected item under your cursor in mini.pick.
  2. Deletes the buffer safely using mini.bufremove.
  3. Re-scans all valid, listed buffers, transforms them into picker items, and forcefully updates the active picker list so it refreshes instantly.

To use it, simply drop this Lua snippet into your mini configuration file:

-- Buffer delete function
local remove_buf = function()
    local item = MiniPick.get_picker_matches().current
    if item == nil then
        return
    end

    -- Delete the buffer safely
    MiniBufremove.delete(item.bufnr)

    -- Rebuild the buffer list dynamically
    local new_items = vim.tbl_map(function(buf)
        return {
            bufnr = buf,
            text = vim.api.nvim_buf_get_name(buf),
        }
    end, vim.api.nvim_list_bufs())

    -- Filter out invalid or unlisted buffers
    new_items = vim.tbl_filter(function(buf)
        return vim.api.nvim_buf_is_valid(buf.bufnr) and vim.bo[buf.bufnr].buflisted
    end, new_items)

    -- Instantly update the picker items view
    MiniPick.set_picker_items(new_items)
end

-- Keymap integration for buffer picking and wiping
map("n", "<leader><Tab>", function()
    MiniPick.builtin.buffers({}, {
        source = {
            show = show_filename,
        },
        mappings = {
            wipeout = {
                char = "<C-d>",
                func = remove_buf,
            },
        },
    })
end)

Want to understand the code?

Let’s break down why this snippet feels so satisfying:

  • MiniPick.get_picker_matches().current: This fetches the exact item your cursor is sitting on inside the active picker window. If nothing is selected, it safely bails out.
  • MiniBufremove.delete(item.bufnr): This asks mini.bufremove to delete the buffer.
  • The Refresher Loop: vim.tbl_map & vim.tbl_filter: Instead of letting the picker retain stale state, this queries Neovim’s internal buffer list (vim.api.nvim_list_bufs()), map them into objects containing the buffer number and file path text, and filter out anything that isn’t a valid, listed buffer (buflisted).
  • MiniPick.set_picker_items(new_items): This is the magic bullet. It feeds the freshly filtered list straight back into the active picker UI, making the deletion feel instantaneous and smooth.
  • The Mapping (<C-d>): Inside the buffer picker, hitting Ctrl + d now triggers our custom remove_buf function, deleting the buffer and refreshing the view without closing the picker modal.

Final Thoughts

This is why configuring Neovim feels like tinkering with a finely tuned instrument. When an ecosystem is built out of clean, modular blocks like mini.nvim, you aren’t boxed into rigid feature sets designed by someone else.

A minor missing feature stops being a roadblock and turns into a fun 5-minute coding puzzle—leaving you with a tool that works precisely the way you want it to. Maybe I was the only one to need this extra feature, but Neovim let me implement it.



Share your feedback via email, using Mastodon or

Comment on wwwgem's post

Copy and paste this URL into the search field of your favourite Fediverse app or the web interface of your Mastodon server.