🔍 Ripgrep Reference

Fast, powerful file searching with rg

Basic Search

rg "pattern"
Search for exact text pattern in current directory
Example: rg "TODO" - finds all TODO comments
rg -i "pattern"
Case-insensitive search
Example: rg -i "error" - finds Error, ERROR, error, etc.
rg "pattern" path/
Search in specific directory
Example: rg "function" src/ - search only in src directory
rg -w "word"
Search for whole words only
Example: rg -w "log" - finds "log" but not "blog"

File Operations

rg --files
List all files that would be searched
Example: rg --files | grep ".py$" - list all Python files
rg -t py "pattern"
Search only in Python files
Example: rg -t py "import" - find imports in Python files
rg -T js "pattern"
Exclude JavaScript files from search
Example: rg -T js "function" - search everywhere except JS files
rg -g "*.txt" "pattern"
Search only files matching glob pattern
Example: rg -g "*.{py,js}" "function" - search .py and .js files
rg --hidden "pattern"
Include hidden files in search
Example: rg --hidden "config" - search including .hidden files
rg -l "pattern"
Show only filenames with matches
Example: rg -l "TODO" - list files containing TODO

Pattern Matching

rg "pat.*tern"
Use regular expressions (default)
Example: rg "func.*\(" - find function declarations
rg -F "literal.string"
Search for literal string (disable regex)
Example: rg -F "3.14" - find exact "3.14", not regex
rg "^pattern"
Match pattern at start of line
Example: rg "^import" - find import statements at line start
rg "pattern$"
Match pattern at end of line
Example: rg ";$" - find lines ending with semicolon
rg "\bpattern\b"
Word boundary matching
Example: rg "\blog\b" - match "log" as whole word
rg -v "pattern"
Invert match (show lines that DON'T match)
Example: rg -v "^#" file.py - show non-comment lines

Output Control

rg -n "pattern"
Show line numbers
Example: rg -n "error" - show matches with line numbers
rg -A 3 -B 3 "pattern"
Show 3 lines after and before each match
Example: rg -A 2 -B 2 "class" - show class with context
rg -C 5 "pattern"
Show 5 lines of context around matches
Example: rg -C 3 "function" - show function with context
rg --no-heading "pattern"
Don't show file headings
Example: rg --no-heading "TODO" - compact output format
rg -c "pattern"
Show count of matches per file
Example: rg -c "import" - count imports per file
rg --color=never "pattern"
Disable colored output
Example: rg --color=never "pattern" > output.txt

Advanced Features

rg -U "pattern.*\n.*pattern"
Multiline search mode
Example: rg -U "class.*\n.*def" - find class followed by method
rg --replace '$1' "capture_group"
Show replacements (preview mode)
Example: rg --replace 'NEW' "old_(\w+)" - preview replacements
rg -z "pattern"
Search in compressed files
Example: rg -z "error" logs.gz - search in gzipped files
rg --stats "pattern"
Show search statistics
Example: rg --stats "function" - show files searched, matches found
rg -j 8 "pattern"
Use 8 threads for parallel search
Example: rg -j 4 "pattern" - faster search on multi-core systems
rg -f patterns.txt
Read patterns from file
Example: rg -f search_patterns.txt - search multiple patterns
rg --max-depth 2 "pattern"
Limit directory traversal depth
Example: rg --max-depth 1 "config" - search only 1 level deep
rg --sort path "pattern"
Sort results by path, modified, accessed, or created
Example: rg --sort modified "pattern" - newest files first
Command copied to clipboard!