Secondary filter on search results

There’s an emacs package (consult) that lets you apply a secondary filter to a list of search results. I’m curious if there’s something similar available to nvim or vim.

To illustrate, this screencast shows a project-wide search where I search for “main”, then filter the results to those that contain “test” or occur in a file whose path contains “test”.

screencast.1672631607

In other words, we run a project-wide search, generating a list of results with accompanying metadata (paths to the files containing results). We then run a secondary query, searching within the results and their metadata.

Is anyone aware of a way to do this kind of search refinement in vim/neovim?

Others will give a better answer than me, but I think you could achieve this by collecting results in a quickfix window [1] and then performing operations on that window [2].

[1] For example, you can use “Telescope grep_string”, and use to send the results to quickfix.

[2] In its native state, a quickfix window is not editable, but there are plugins to address this, like (IIRC) nvim-bqf (“better quickfix”), and I think others. I haven’t tried them but want to one day. With this, you could presumably filter the quickfix list easily with something like :v/text/d to get rid of non-matches.