TL;DR — Quick Summary
ripgrep (rg) searches file contents recursively and respects .gitignore. 10x faster than grep, with sane defaults, regex, and type filtering.
ripgrep is the search tool you’ll use every day. Type rg TODO and it instantly finds every TODO across your codebase — skipping node_modules, .git, and binaries automatically.
Installation
# macOS
brew install ripgrep
# Arch Linux
sudo pacman -S ripgrep
# Ubuntu/Debian
sudo apt install ripgrep
# Cargo
cargo install ripgrep
Usage
# Search recursively (default)
rg TODO
rg 'function.*async'
rg 'import.*React'
# Case insensitive
rg -i 'error'
# Smart case (case-insensitive unless uppercase present)
rg -S 'Error'
# Search specific file types
rg -t py 'import'
rg -t ts 'interface'
rg -t rust 'fn main'
rg -t md 'TODO'
# Exclude file types
rg -T js 'function'
# Include hidden files and .gitignore'd files
rg --hidden --no-ignore 'secret'
# Show context (lines before/after)
rg -C 3 'TODO' # 3 lines context
rg -B 2 'error' # 2 lines before
rg -A 5 'function' # 5 lines after
# Count matches
rg -c 'TODO'
# Files only (no line content)
rg -l 'TODO'
# Replace preview (doesn't modify files)
rg 'oldFunc' -r 'newFunc'
# Fixed strings (no regex)
rg -F 'array[0]'
# Multiline search
rg -U 'fn.*\n.*return'
# JSON output
rg --json 'pattern'
# Glob filtering
rg 'TODO' -g '*.ts' -g '!*.test.ts'
Comparison
| Feature | ripgrep | grep -r | ag | ack |
|---|---|---|---|---|
| Speed | Fastest | Slow | Fast | Moderate |
| .gitignore | Yes | No | Yes | No |
| Unicode | Yes | Varies | Yes | Yes |
| Type filter | Yes (-t) | No | Yes | Yes |
| Replace | Preview | No | No | No |
| Smart case | Yes (-S) | No | Yes | Yes |
Summary
- ripgrep (rg) searches code 2-10x faster than grep with sane defaults
- Respects .gitignore, skips binaries and hidden files automatically
- Type filtering (-t py, -t ts, -t rust) for language-specific searches
- Smart case, context lines, replace preview, glob filtering
- Integrates with bat, fzf, and most editors (VS Code uses rg internally)