| name | ripgrep |
| description | Fast content search with rg (ripgrep) — correct flags, regex engine, ignore behavior, type filtering, and common misuse patterns to avoid |
| license | MIT |
| compatibility | opencode |
| metadata | {"audience":"developers","workflow":"search"} |
ripgrep (rg) Skill
rg searches file contents using regex. It is Rust-based, respects .gitignore automatically, and is parallel by default. Use it instead of grep.
Mental Model
| Question | Answer |
|---|
| What does rg search? | File contents (not names — use fd for names) |
| Default pattern type | Regex (Rust regex crate — no lookahead/backrefs) |
| Files skipped by default | Hidden files, .gitignore matches, binary files |
| How to search everything | -uuu (unrestricted × 3) |
Core Flags (Daily Use)
Pattern Control
rg "pattern"
rg -F "literal.string"
rg -e "pat1" -e "pat2"
rg -f patterns.txt
rg -P "(?<=foo)bar"
Case
rg -i "pattern"
rg -s "pattern"
rg -S "pattern"
Output Shape
rg -l "pattern"
rg -c "pattern"
rg -n "pattern"
rg -N "pattern"
rg -o "pattern"
rg -C 3 "pattern"
rg -A 2 -B 1 "pattern"
rg --json "pattern"
Scope Control
rg "pattern" src/
rg "pattern" file.rb
rg --hidden "pattern"
rg -L "pattern"
rg -d 2 "pattern"
rg --max-filesize 1M "p"
rg -j 4 "pattern"
File Type Filtering
rg -t ruby "pattern"
rg -T ruby "pattern"
rg --type-list
rg --type-add 'haml:*.haml' -t haml "pattern"
rg -g "*.rb" "pattern"
rg -g "!*.min.js" "p"
Ignore / Visibility Behavior
ripgrep skips by default (in precedence order):
.rgignore (highest priority)
.ignore
.gitignore (including global git config + parent dirs)
- Hidden files/dirs
- Binary files (NUL-byte heuristic)
When rg "misses" something:
rg --hidden "pattern"
rg --no-ignore "pattern"
rg -u "pattern"
rg -uu "pattern"
rg -uuu "pattern"
rg -a "pattern"
Regex Engine: Default vs PCRE2
| Feature | Default (Rust regex) | PCRE2 (-P) |
|---|
| Lookahead/lookbehind | ❌ | ✅ |
| Backreferences | ❌ | ✅ |
| Speed | Faster (linear time) | Slower |
| Unicode | Full | Full |
Rule: Use default engine unless you specifically need lookahead/backrefs. PCRE2 can be significantly slower on large codebases.
rg -P "(?<=def )(\w+)"
rg --engine auto "pat"
Config File
ripgrep does not auto-discover config. You must set the env var:
export RIPGREP_CONFIG_PATH="$HOME/.config/ripgrep/rc"
Format — one flag per line, # comments:
# ~/.config/ripgrep/rc
--smart-case
--hidden
--type-add=haml:*.haml
CLI flags always override config. Disable config: rg --no-config "pattern".
Common Misuse Patterns (AVOID)
❌ Using grep instead of rg
grep -r "pattern" app/
rg "pattern" app/
❌ Forgetting -F for literal strings with special chars
rg "user.rb" src/
rg "arr[0]" src/
rg -F "user.rb" src/
rg -F "arr[0]" src/
❌ Expecting lookahead/lookbehind without -P
rg "(?<=def )\w+" src/
rg -P "(?<=def )\w+" src/
❌ Searching hidden/ignored files without flags
rg "SECRET" .
rg --hidden "SECRET" .
rg -uu "SECRET" .
❌ Using --type-add expecting it to persist
rg --type-add 'haml:*.haml' -t haml "pattern"
rg -t haml "pattern"
❌ Piping rg output and expecting consistent ordering
rg -l "pattern" | head -1
rg --sort path -l "pattern" | head -1
❌ Using -c to count total matches (it counts lines)
rg -c "pattern"
rg --count-matches "pattern"
Practical Recipes (GitLab Codebase)
rg "def (self\.)?authenticate" app/
rg -w "UserPolicy" app/ spec/
rg -t ruby -l "has_many :projects"
rg -t ruby -g "!spec/" "# (TODO|FIXME)"
rg -uu "lodash" --type js
rg "require.*auth_helper" -t ruby -l
rg -e "class.*Controller" -e "module.*Controller" app/controllers/
rg "old_method" --replace "new_method" src/
Performance Tips
- Narrow the path — always pass a directory, not
. when possible
- Use
-t type filters before broad patterns
- Avoid
-P (PCRE2) unless you need it — measurably slower on large repos
- Avoid
--pre (runs a process per file) — use --pre-glob to limit scope if needed
- Avoid
--sort for large searches — it disables parallelism
-l (files only) is faster than full content output when you just need file paths