Blog Search your whole codebase fast with ripgrep

Search your whole codebase fast with ripgrep

2 min read

Search your whole codebase fast with ripgrep
TL;DR ripgrep (rg) is a fast code search tool that skips ignored files by default. Learn a handful of flags: filter by file type, show context lines, match whole words, and list only filenames. It turns a slow grep crawl into an instant answer.

Once you have used ripgrep, plain grep on a big repo feels like waiting for a fax. rg searches huge trees almost instantly and skips the junk you never meant to search. A few flags cover most of what you need.

The default that makes it fast

rg is recursive by default and respects your .gitignore, so it skips node_modules, build output, and anything else you ignore, without you asking.

rg "useEffect"

That searches your whole project, minus the noise, in a blink.

Filter by file type

Narrow the search to the language you care about.

rg -t js "fetch("      # only JavaScript
rg -T test "TODO"      # skip test files

Run rg --type-list to see the built-in types.

See the surrounding lines

Context turns a match into something you can actually read.

rg -C 3 "throw new Error"   # 3 lines before and after

Use -B for lines before and -A for lines after when you only want one side.

Match whole words and be case-smart

rg -w "id"          # match "id" as a word, not "width" or "hidden"
rg -i "readme"      # case-insensitive

By default rg is case-sensitive unless you pass -i, or smart-case if you configure it.

Just the filenames

When you want to know which files match, not every line:

rg -l "deprecated"

Great for feeding a list into another command.

When you need the ignored stuff

Sometimes the thing you are hunting is in an ignored file.

rg --hidden --no-ignore "secret"

That searches dotfiles and ignored paths too, for the rare cases you need them.

Why it is worth the switch

The speed changes how you work. When search is instant, you search more, guess less, and find the real definition instead of grepping around it. Learn these few flags and rg becomes the fastest way to answer "where is this used?"

FAQ

How is ripgrep different from grep?

ripgrep is much faster on large trees and respects your .gitignore by default, so it skips build output and dependencies without extra flags. It also has convenient defaults like recursive search and file-type filters.

Does ripgrep search hidden or ignored files?

Not by default, which is usually what you want. Add --hidden to include dotfiles and --no-ignore to search files your .gitignore excludes, for the times you actually need them.

Can I limit ripgrep to certain file types?

Yes. Use -t to include a type and -T to exclude one, for example rg -t js pattern to search only JavaScript, or rg -T test to skip test files.