ripgrepis a line-oriented search tool that recursively searches the current directory for a regex pattern.
I use ripgrep constantly - it’s one of those tools that just gets out of your way and finds what you need. It’s faster than grep, respects .gitignore by default, and has sensible defaults that actually make sense.
Why ripgrep?
The big wins over traditional grep:
- It’s blazing fast - seriously, try searching a large codebase
- Respects
.gitignore- skips node_modules, build artifacts automatically - Smart defaults - skips binaries, hidden files unless you ask
- Better regex engine - supports look-around and other modern features
- File type filtering - search only Python files, only JavaScript, etc.
Real-world examples
Basic searching
Find a function definition across your entire project:
$ rg 'def calculate_thrust'
propulsion/engine.py
47:def calculate_thrust(pressure, area, ambient):
control/simulation.py
122:def calculate_thrust_vector(engines):
Case-insensitive search when you’re not sure about casing:
$ rg -i 'readme'
README.md
1:# Project README
docs/setup.md
15:See README for installation
Working with specific files
Search only in Python files:
$ rg 'import numpy' --type py
analysis/trajectory.py
1:import numpy as np
tests/test_dynamics.py
3:import numpy as np
Or use glob patterns for more control:
$ rg 'TODO' -g '*.rs' -g '!target/*'
src/main.rs
45: // TODO: implement error handling
src/lib.rs
78: // TODO: optimize this loop
Understanding your matches
Show context around matches to understand the code better:
$ rg 'launch_sequence' -B2 -A2
firmware/startup.c
142- initialize_systems();
143- verify_sensors();
144: launch_sequence();
145- monitor_telemetry();
146- enter_main_loop();
Just need to know which files contain something?
$ rg 'unsafe' --files-with-matches
src/memory.rs
src/ffi.rs
src/low_level.rs
Count occurrences to see how widespread something is:
$ rg 'deprecated' --count
src/legacy.py:3
src/old_api.py:7
tests/compat.py:1
Advanced patterns
Find class definitions using regex:
$ rg '^class \w+Engine'
engines/raptor.py
12:class RaptorEngine(BaseEngine):
engines/merlin.py
8:class MerlinEngine(BaseEngine):
Find all TODO comments with context:
$ rg 'TODO|FIXME|HACK' --type-add 'code:*.{py,js,rs,go}' -t code
Other useful patterns
Exclude multiple directories:
$ rg 'api_key' -g '!{test,vendor,node_modules}/*'
Search for multiple patterns:
$ rg -e 'error' -e 'warning' -e 'critical'
My ripgrep config
I keep a .ripgreprc in my home directory:
# ~/.ripgreprc
# Add custom types
--type-add=docker:Dockerfile*
--type-add=terraform:*.{tf,tfvars}
# Set default colors
--colors=match:fg:yellow
--colors=line:fg:green
# Always show line numbers
--line-number
# Search hidden files but respect .gitignore
--hidden
Some tips
- Use
rg --filesto list all files that would be searched (great for piping to other commands) - Add
--no-headingfor cleaner output when piping - Use
-rfor replacements:rg 'foo' -r 'bar'shows what would be replaced - The
-Fflag searches for literal strings instead of regex (faster for fixed strings) - JSON output with
--jsonfor tooling integration
Once you get used to ripgrep, regular grep feels pretty slow in comparison.