Software Engineer's Blog

ripgrep (rg): The Fastest Way to Search Your Code

ripgrep (rg): The Fastest Way to Search Your Code

You run grep -R "handler" . in a Node or Rust project and it grinds for seconds, then buries the one match you wanted under a wall of hits from node_modules/ and target/. ripgrep (rg) fixes both problems at once, which is why a lot of developers stop reaching for grep -R on codebases.

ripgrep (rg) is a search tool written in Rust. The headline is speed, but the speed comes from doing less work, not just running the same work faster.

Why ripgrep?

1. It searches fewer files

Most of rg’s real-world advantage over grep -R isn’t raw scanning speed — it’s that rg skips what you’d never want to search anyway. It obeys your .gitignore, so anything listed there (node_modules/, target/, build output) is skipped, and it ignores .git/ and binary files by default too. On a big repo that’s the difference between searching 2,000 files and 200,000.

2. A regex engine that can’t blow up

rg uses Rust’s regex crate, which is built on finite automata and guarantees linear-time matching. Classic backtracking engines can hit catastrophic slowdowns on patterns like (a+)+; rg’s default engine simply can’t. (When you need lookaround, -P switches to PCRE2, which trades that guarantee back.)

3. Respects .gitignore

Because it obeys ignore rules by default, results stay clean without a pile of --exclude flags. Need to bypass that? The flags stack: -u stops respecting ignore rules, -uu also searches hidden files, and -uuu searches everything, binaries included.

3. Recursive by Default

No need for grep -R. Just run:

rg "keyword"

4. Colorful and Easy to Read

Results come with file names, line numbers, and syntax highlighting right out of the box.

Basic Examples

Find text in all files (Smart Case)

rg -i "error"

Search only in specific file types

rg "import" -t python

Show context (2 lines before and after)

rg "functionName" -C 2

Use regex (PCRE2)

rg -P "(foo|bar)+"

Installation

  • macOS: brew install ripgrep
  • Ubuntu: sudo apt install ripgrep
  • Windows: scoop install ripgrep (or via Chocolatey)

When grep is still the right call

rg isn’t a total replacement, and pretending otherwise gets you stuck. grep is POSIX — it’s on virtually every Linux box and production server with nothing to install (bare scratch/distroless containers being the exception). rg usually isn’t. So for a quick one-off on a remote host, or inside a shell script you want to run anywhere, grep is the portable choice. Install rg on the machines you actually work on; assume grep is already there everywhere else.

There’s also the ignore behavior itself: rg skipping .gitignored files is exactly what you don’t want when you’re grepping build artifacts or logs. Reach for grep, or pass rg -uuu, when you genuinely need to see everything. And if you live in the terminal, rg pairs well with an editor like Vim for jumping straight to matches.

Summary

For searching a codebase you’re actively working in, rg is faster in practice, skips the noise by default, and can’t fall into regex blowups. Keep grep in your pocket for portability and for the times you actually want to search the files rg hides.