| name | cli-ripgrep |
| description | Covers effective use of ripgrep (rg) for fast regex search across codebases. Covers rg PATTERN, -i, -w, -l, -c, -n, --type, -g, -A/-B/-C, -U multiline, --json, type-add, .ripgreprc, replacement, and PCRE2. Activates when the user asks about ripgrep, rg, fast code search, or searching file contents with regex while respecting .gitignore.
|
ripgrep (rg) — Fast Regex Search
Repo: https://github.com/BurntSushi/ripgrep
ripgrep recursively searches directories for a regex pattern. It is faster than
grep/ack/ag, respects .gitignore by default, and outputs colorized results.
Drop-in replacement for grep -r in virtually all code-search workflows.
When to Activate
Manual triggers:
- "How do I use ripgrep / rg?"
- "Search for a pattern across my codebase"
- "Find all files containing X"
Auto-detect triggers:
- User wants to search file contents recursively in a project
- User wants to filter results by file type or extension
- User needs multiline or PCRE2 regex search
- User wants to pipe search results to jq or fzf
Key Commands
Basic Search
rg 'TODO'
rg 'TODO' src/
rg 'TODO' src/app.ts
rg 'func\w+' --type=go
rg -i 'error'
rg -w 'log'
rg -F 'foo.bar'
Controlling Output
rg -l 'TODO'
rg -L 'TODO'
rg -c 'TODO'
rg -n 'TODO'
rg --no-filename 'TODO'
rg --no-heading 'TODO'
rg -o 'v\d+\.\d+\.\d+'
rg --max-count=1 'TODO'
Context Lines
rg -A 3 'def main'
rg -B 3 'def main'
rg -C 5 'panic'
File Type Filtering
rg 'import' --type=js
rg 'import' -t js -t ts
rg 'import' --type-not=json
rg 'TODO' -g '*.md'
rg 'TODO' -g '!*.test.*'
rg 'secret' -g '**/.env*'
Custom Type Definitions
rg --type-add 'web:*.{html,css,js,ts}' -t web 'className'
Multiline Search (-U)
rg -U 'function\s+\w+\s*\([^)]*\)\s*\{' --type=js
rg -U 'SELECT.*\n.*FROM'
JSON Output
rg --json 'TODO'
rg --json 'TODO' | jq 'select(.type=="match") | .data.lines.text'
rg --json -l 'FIXME' | jq -r 'select(.type=="begin") | .data.path.text'
Replacement (non-destructive preview)
rg 'foo' --replace 'bar'
rg 'v(\d+)' --replace 'version-$1'
rg -l 'oldName' | xargs sed -i '' 's/oldName/newName/g'
PCRE2 (advanced regex)
rg -P '(?<=def )\w+'
rg -P '\bfoo\b(?!bar)'
rg -P '(\w+)\s+\1'
Hidden Files & Ignored Paths
rg -H 'secret' --hidden
rg 'TODO' -I
rg 'TODO' --no-ignore
rg 'TODO' --no-ignore-vcs
rg 'TODO' -u
rg 'TODO' -uuu
Searching Compressed / Stdin
rg 'error' --search-zip file.gz
cat file.log | rg 'ERROR'
Advanced Patterns
Find All TODOs Across a Project (structured)
rg --json 'TODO:\s*(.+)' | \
jq -r 'select(.type=="match") | [.data.path.text, (.data.line_number|tostring), .data.submatches[0].match.text] | @tsv'
List All Imported Packages (Node)
rg --no-filename -o "from ['\"]([^'\"]+)['\"]" -r '$1' --type=ts | sort -u
Find Large Functions (heuristic: > 50 lines between braces)
rg -n '^(export\s+)?(async\s+)?function ' --type=ts
Search + Immediate Edit (with fzf)
rg --line-number '' | \
fzf --delimiter ':' \
--preview 'bat --color=always --highlight-line {2} {1}' | \
awk -F: '{print $1 " +" $2}' | xargs $EDITOR
.ripgreprc Config File
--type-add=web:*.{html,css,js,ts,jsx,tsx,vue,svelte}
--type-add=config:*.{json,yaml,yml,toml,ini}
--smart-case
--hidden
--glob=!.git/
--glob=!node_modules/
--glob=!dist/
--colors=path:fg:blue
--colors=match:fg:red
--colors=match:style:bold
Practical Examples
Find All API Endpoints in a Node Project
rg "(app|router)\.(get|post|put|delete|patch)\s*\(" --type=js --type=ts -n
Find Hardcoded Secrets (naive scan)
rg -i '(password|secret|api_key|token)\s*[:=]\s*["\x27][^\s"]+["\x27]' \
--glob='!*.test.*' --glob='!*.spec.*'
Count Lines of Code by Type
rg '' --type=ts -l | xargs wc -l | sort -rn | head -20
Diff Search: What Changed in Last Commit
git diff HEAD~1 | rg '^\+.*TODO'
Chaining with Other Skills
- fd (cli-fd): Use
fd to select a file set, then pipe to rg for content search — e.g., fd -e ts | xargs rg 'useEffect'
- jq: Pipe
rg --json output to jq for structured extraction of match text, file, and line numbers
- fzf (cli-fzf): Pipe
rg results into fzf for interactive navigation directly to the matched line in your editor