How do I narrow an existing location list to only entries matching a regex without rerunning the search?
Answer
:packadd cfilter | Lfilter /pattern/
Explanation
When you already have a populated location list, rerunning the original search just to focus on a subset is slow and disruptive. The built-in cfilter plugin lets you refine that list in place using a regex, which is ideal when you are triaging a large result set. This is especially useful in review or refactor workflows where you keep broad matches first, then progressively narrow to the exact ones you want to touch.
How it works
:packadd cfilterloads Vim's optionalcfilterplugin for the current sessionLfilter /pattern/filters the current location list to entries that matchpattern- The filter acts on list entries, not raw file content, so it is very fast after the initial search
- You can refine repeatedly with different patterns as you narrow the target set
Example
Start with a location list created from a broad search:
src/a.lua:12: TODO(api): remove legacy parser
src/b.lua:48: TODO(ui): update dropdown behavior
src/c.lua:77: FIXME(api): handle nil response
src/d.lua:91: TODO(api): validate payload schema
Run:
:packadd cfilter | Lfilter /TODO(api)/
Now the location list is reduced to:
src/a.lua:12: TODO(api): remove legacy parser
src/d.lua:91: TODO(api): validate payload schema
Tips
- Use
Cfilterfor quickfix lists andLfilterfor location lists - Keep broad searches broad; filter after the fact for faster iteration
- Combine with
:lolderand:lnewerto navigate list history when iterating