helix icon indicating copy to clipboard operation
helix copied to clipboard

Add optional substring matching for picker

Open pascalkuthe opened this issue 1 year ago • 0 comments

This PR implements common syntax that allows matching substrings instead of fuzzy matching. I will quote the fzf README here for an explanation what exactly this does:

Token Match type Description
sbtrkt fuzzy-match Items that match sbtrkt
'wild exact-match (quoted) Items that include wild
^music prefix-exact-match Items that start with music
.mp3$ suffix-exact-match Items that end with .mp3
!fire inverse-exact-match Items that do not include fire
!^music inverse-prefix-exact-match Items that do not start with music
!.mp3$ inverse-suffix-exact-match Items that do not end with .mp3

All of these can be escaped by inserting a backslash \!, \^, \' and \$ (not mentioned in the README but tested in practice). The implementation here closely matches the behavior of both fzf and skim (which behave identical)

I found myself needing these recently. In particular, I found myself missing the inverse matches. I work on a circuit simulator (ngspice) which has some core code and then some device models (also just c code). When I was refactoring core parts of the simulator I wanted to use gr to find all references. However, this was polluted by thousands of references in the device models (all of which are inside the devices folder). So just being able to add ^devices in the picker was invaluable.

While looking into this I found myself warming up to the other options as well, for example with #5110 ^E can be used to filter only errors or !^H can be used to ignore hints.

pascalkuthe avatar Dec 10 '22 23:12 pascalkuthe