ripgrep
Recursively search directories for a regex pattern, blazingly fast
Description
ripgrep (rg) is a line-oriented search tool that recursively searches the current directory for a regex pattern. It respects .gitignore rules and automatically skips hidden files, binary files, and directories. It's consistently faster than alternatives like grep, ag, git grep, and ack.
Install
brew install ripgrepsudo apt install ripgrepsudo pacman -S ripgrepcargo install ripgrepAI Summary
Ultra-fast recursive regex search. Drop-in grep replacement that respects .gitignore, skips binary files, and searches orders of magnitude faster than grep -r.
Capabilities
- + Recursive directory search with regex patterns
- + Automatic .gitignore and .ignore file respect
- + Searches compressed files
- + File type filtering (--type rust, --type py)
- + Multi-line search support
- + JSON output for programmatic consumption
- + Replacement text support (--replace)
Use When
- → Searching for text patterns across a codebase
- → Need a fast grep replacement that respects gitignore
- → Searching with file type filters
- → Need structured (JSON) search output for scripting
Avoid When
- x Need to search a single file (grep is fine)
- x Need full PCRE2 features without --pcre2 flag
- x Searching binary file contents intentionally
Usage Patterns
Search for a pattern in current directory
rg 'pattern' Recursively search all text files for pattern
Search only in specific file types
rg --type rust 'fn main' Search only Rust files for main functions
Search and replace (dry run)
rg 'old_name' --replace 'new_name' Shows what replacements would look like (doesn't modify files)
Get file list with matches
rg -l 'TODO' List files containing TODO comments
Input / Output
0 Matches found 1 No matches found 2 Error occurred Typical Pipelines
rg -l 'pattern' | fzf --preview 'rg --color=always pattern {}' rg --json 'TODO' | jq '.data.lines.text' rg 'import.*from' --type ts -c | sort -t: -k2 -rn | head