Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

75%
+4 −0
Q&A Fuzzy search through multiple files

When I do rg foo /bar/baz/, ripgrep will search for foo in all files under /bar/baz/. For every file that has matching lines, it will print each line with its line number, highlight the matching pa...

0 answers  ·  posted 22d ago by matthewsnyder‭

Question search
#1: Initial revision by user avatar matthewsnyder‭ · 2025-05-24T19:55:22Z (22 days ago)
Fuzzy search through multiple files
When I do `rg foo /bar/baz/`, ripgrep will search for `foo` in all files under `/bar/baz/`. For every file that has matching lines, it will print each line with its line number, highlight the matching part, and also caption the lines with the name of the file as well. The filenames are a different color to make them stand out more. I can use the `--context`, `--after-context`, `--before-context` lines to include additional lines around the matching line.

This is great but the one problem is it's an exact search. How can I do the same thing, with the same type of output, but fuzzy instead?

It seems like fzf should help, but I have no idea what magic incantation of fzf arguments is needed for this. I would need it to be not interactive (so that I can use it in pipelines and scripts), include line numbers and file names just like ripgrep, have an option for context just like ripgrep, ideally colorize like ripgrep.

I suppose with fuzzy matching, it is arbitrary what to consider a "match", and technically all lines of all files are a "weak match". But by default fzf appears to have some cutoff, and I'm okay with just using that.