| name | ripgrep |
| description | This skill should be used when the user asks about "ripgrep", "rg command", "fast grep", "search files", "code search", "regex search in files", "find in files", "search codebase", "grep replacement", or needs guidance on file content searching, pattern matching, or recursive text search. Provides command reference, usage patterns, and best practices for ripgrep (rg). |
ripgrep (rg) CLI Reference
ripgrep is a line-oriented search tool that recursively searches directories for regex patterns. It respects .gitignore rules by default and automatically skips hidden files, directories, and binary files.
Basic Usage
rg 'pattern'
rg 'pattern' file.txt
rg 'pattern' src/
rg 'pattern' src/ tests/ docs/
Essential Flags
| Flag | Short | Description |
|---|
--ignore-case | -i | Case-insensitive search |
--smart-case | -S | Case-insensitive unless pattern has uppercase |
--word-regexp | -w | Match whole words only |
--fixed-strings | -F | Treat pattern as literal string (no regex) |
--count | -c | Show count of matches per file |
--files-with-matches | -l | Show only filenames with matches |
--files-without-match | -L | Show only filenames without matches |
--line-number | -n | Show line numbers (default when output is terminal) |
--no-line-number | -N | Suppress line numbers |
--only-matching | -o | Print only the matched text |
--invert-match | -v | Show non-matching lines |
--multiline | -U | Enable multiline matching (. matches newlines) |
Context Lines
rg -A 3 'pattern'
rg -B 3 'pattern'
rg -C 3 'pattern'
File Filtering
By File Type
rg 'pattern' --type rust
rg 'pattern' -trust
rg 'pattern' --type-not js
rg 'pattern' -Tjs
rg --type-list
rg --type-add 'web:*.{html,css,js}' -tweb 'pattern'
Common built-in types: py, js, ts, rust, go, java, c, cpp, html, css, json, yaml, md, sh
By Glob Pattern
rg 'pattern' -g '*.toml'
rg 'pattern' -g 'src/**/*.rs'
rg 'pattern' -g '!*.min.js'
rg 'pattern' -g '*.rs' -g '*.toml'
Automatic Filtering Control
ripgrep automatically ignores:
- Files matching
.gitignore, .ignore, .rgignore patterns
- Hidden files and directories
- Binary files
rg --no-ignore 'pattern'
rg --hidden 'pattern'
rg -. 'pattern'
rg --text 'pattern'
rg -a 'pattern'
rg -u 'pattern'
rg -uu 'pattern'
rg -uuu 'pattern'
Regex Patterns
ripgrep uses Rust regex syntax by default.
rg '\w+\d+'
rg '^start'
rg 'end$'
rg '[A-Z][a-z]+'
rg 'foo|bar'
rg 'colou?r'
rg 'a+'
rg 'a*'
rg 'a{2,4}'
rg 'a+?'
rg -P '(?<=prefix)\w+'
rg -P '\w+(?=suffix)'
PCRE2 Mode
Enable PCRE2 for advanced regex features:
rg -P 'pattern'
rg --pcre2 'pattern'
rg --engine auto 'pattern'
Multiline Search
rg -U 'start.*end'
rg -UP 'function\s+\w+\s*\([^)]*\)\s*\{'
Replacements (Output Only)
ripgrep never modifies files. The --replace flag transforms output only.
rg 'old' -r 'new'
rg '(\w+)@(\w+)' -r '$2:$1'
rg '(?P<user>\w+)@(?P<domain>\w+)' -r '$domain:$user'
Output Formats
rg --json 'pattern'
rg -l --null 'pattern'
rg -l 'pattern'
rg --files
rg --files -g '*.rs'
Performance Options
rg --max-depth 3 'pattern'
rg --max-count 5 'pattern'
rg 'pattern' | head -n 100
rg --no-mmap 'pattern'
rg --sort path 'pattern'
Common Patterns
Find function definitions
rg '^(pub\s+)?(async\s+)?fn\s+\w+'
rg '^def \w+|^class \w+'
rg '(function|const|let|var)\s+\w+\s*='
Find TODO/FIXME comments
rg 'TODO|FIXME|XXX|HACK' -g '!*.min.*'
Find imports/requires
rg '^(import|from)\s+\w+'
rg "^(import|require\()"
rg '^import\s+'
Search specific patterns
rg '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
rg '\w+@\w+\.\w+'
rg 'https?://[^\s]+'
Configuration File
Set default options via RIPGREP_CONFIG_PATH:
export RIPGREP_CONFIG_PATH="$HOME/.ripgreprc"
Example ~/.ripgreprc:
--smart-case
--hidden
--glob=!.git/*
--max-columns=150
--max-columns-preview
Debugging
rg --debug 'pattern'
rg --no-config 'pattern'
Key Differences from grep
| Feature | ripgrep | GNU grep |
|---|
| Recursive by default | Yes | No (-r required) |
| Respects .gitignore | Yes | No |
| Skips binary files | Yes | No |
| Unicode by default | Yes | Depends on locale |
| Parallel search | Yes | No |
| Memory-mapped files | Yes | No |
Reference
For advanced features, see: