Skip to content

[idea] :QfFilter — narrow quickfix list entries by Lua pattern #296

Description

@stanfish06

What

Add a :QfFilter {pattern} user command that filters the current quickfix list in-place, keeping only entries whose message text or filename matches a Lua pattern.

Where

lua/config/options.lua — alongside the existing :Compile command and <leader>co/cc keymaps (around lines 159–169).

Why it matters

The config uses quickfix heavily: :Compile populates it with build or grep output, and <leader>co/cc open/close it. After a large make run or wide vimgrep, the list can contain hundreds of entries. There is no built-in way to narrow it without re-running the original command with a tighter query.

Example use cases:

  • :QfFilter error — keep only lines containing "error" after a build
  • :QfFilter foo%.c — keep only entries from foo.c
  • :QfFilter undefined — isolate one class of linker error from a noisy build

The <leader>cf keymap (mnemonic: close/clear → clean/filter) could be a natural extension point, but the command alone is already useful via cmdline completion.

Recommended action

Add to lua/config/options.lua:

vim.api.nvim_create_user_command("QfFilter", function(opts)
    local pattern = opts.args
    local items = vim.fn.getqflist()
    local filtered = vim.tbl_filter(function(item)
        local text = item.text or ""
        local fname = vim.fn.bufname(item.bufnr) or ""
        return text:find(pattern) ~= nil or fname:find(pattern) ~= nil
    end, items)
    vim.fn.setqflist(filtered, "r")
    if #filtered > 0 then
        vim.cmd("copen")
    else
        vim.notify("QfFilter: no entries match " .. vim.inspect(pattern), vim.log.levels.WARN)
    end
end, { nargs = 1, desc = "Filter quickfix list by Lua pattern" })

A companion :QfRestore that reverts to the last unfiltered list (stored in a module-level variable) would round out the feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions