« Back to Index

Vim: filter quickfix/location list results

View original Gist on GitHub

Tags: #vim #filter #quickfix #locationlist

filter vim quickfix location list results.md

:packadd cfilter
:Cfilter! /xyz/

The ! is like grep -v.

So :Cfilter /xyz/ would filter the results so only those items that have xyz will be kept. If you add the ! then the results will be everything except xyz.

NOTE: if you’re using something like Ack/Ag then you can use that tools own filtering flags, but if that’s not appropriate for whatever reason, then this solution is very useful.

A ‘pattern’ is basic regex syntax by default (you can get \v magic/advanced variation too).

So by default it means, for example, a regex quantifier like + will need to be escaped \+.

So if you use the basic syntax you’ll find * is easier to work with as it doesn’t need escaping:

:Cfilter! '.*/common/.*'

Compared to:

:Cfilter! '.\+/common/.\+'

But \v helps for more advanced regex syntax:

:Cfilter! '\v.+/common/.+'

NOTE: I’ve used ' single quotes as delimeters as I was filtering content that looked like unix file paths.

Refer to :help cfilter-plugin for more information.