一键导入
ripgrep
Fast content search with rg (ripgrep) — correct flags, regex engine, ignore behavior, type filtering, and common misuse patterns to avoid
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Fast content search with rg (ripgrep) — correct flags, regex engine, ignore behavior, type filtering, and common misuse patterns to avoid
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Writing, running, and debugging RSpec specs in the GitLab monorepo — commands, patterns, undercoverage, system specs, and GitLab-specific conventions
Fast file name search with fd — correct pattern modes, type filters, ignore behavior, exec patterns, and common misuse to avoid
Extract and analyze all failures from the most recent GitLab pipeline
Working with GitLab security policies — reading, writing, gnerating security policies including approval policies, scan execution policies
GitLab workflow automation using glab CLI
Generate GitLab MR descriptions matching the project's writing conventions — includes database queries, background context, series references, and validation steps
| 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"} |
rg searches file contents using regex. It is Rust-based, respects .gitignore automatically, and is parallel by default. Use it instead of grep.
| 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) |
rg "pattern" # regex search (default)
rg -F "literal.string" # fixed string — no regex parsing (use for dots, brackets, etc.)
rg -e "pat1" -e "pat2" # multiple patterns (OR)
rg -f patterns.txt # patterns from file (one per line)
rg -P "(?<=foo)bar" # PCRE2 — enables lookahead/lookbehind/backreferences
rg -i "pattern" # case-insensitive
rg -s "pattern" # case-sensitive (explicit)
rg -S "pattern" # smart-case: insensitive if all lowercase, sensitive if mixed
rg -l "pattern" # list matching files only (no content)
rg -c "pattern" # count matching lines per file
rg -n "pattern" # show line numbers (default when TTY)
rg -N "pattern" # suppress line numbers
rg -o "pattern" # print only the matching part
rg -C 3 "pattern" # 3 lines context (before + after)
rg -A 2 -B 1 "pattern" # 2 after, 1 before
rg --json "pattern" # JSON output (great for scripting/tooling)
rg "pattern" src/ # search in directory
rg "pattern" file.rb # search single file
rg --hidden "pattern" # include hidden files/dirs (dotfiles)
rg -L "pattern" # follow symlinks
rg -d 2 "pattern" # max depth 2
rg --max-filesize 1M "p" # skip files larger than 1MB
rg -j 4 "pattern" # use 4 threads
rg -t ruby "pattern" # only Ruby files
rg -T ruby "pattern" # exclude Ruby files
rg --type-list # list all built-in types
rg --type-add 'haml:*.haml' -t haml "pattern" # custom type (current invocation only)
rg -g "*.rb" "pattern" # glob include
rg -g "!*.min.js" "p" # glob exclude (! prefix)
ripgrep skips by default (in precedence order):
.rgignore (highest priority).ignore.gitignore (including global git config + parent dirs)When rg "misses" something:
rg --hidden "pattern" # include dotfiles
rg --no-ignore "pattern" # disable all ignore files
rg -u "pattern" # = --no-ignore
rg -uu "pattern" # = --no-ignore --hidden
rg -uuu "pattern" # = --no-ignore --hidden --binary (search everything)
rg -a "pattern" # treat binary as text (risky — can produce garbage output)
| 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+)" # PCRE2 lookbehind — find method names after "def"
rg --engine auto "pat" # auto-selects PCRE2 only if pattern requires it
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".
# WRONG
grep -r "pattern" app/
# CORRECT
rg "pattern" app/
# WRONG — dots match any char, brackets are char classes
rg "user.rb" src/
rg "arr[0]" src/
# CORRECT
rg -F "user.rb" src/
rg -F "arr[0]" src/
# WRONG — default engine has no lookahead
rg "(?<=def )\w+" src/
# CORRECT
rg -P "(?<=def )\w+" src/
# WRONG — .env, .git, node_modules etc. are skipped silently
rg "SECRET" .
# CORRECT (if you need hidden files)
rg --hidden "SECRET" .
# CORRECT (if you need ignored dirs too)
rg -uu "SECRET" .
# WRONG — --type-add only applies to current invocation
rg --type-add 'haml:*.haml' -t haml "pattern" # works now
rg -t haml "pattern" # FAILS next time — type not defined
# CORRECT — put --type-add in config file or alias
# WRONG — parallel search = non-deterministic order
rg -l "pattern" | head -1 # may return different file each time
# CORRECT — sort for determinism (disables parallelism)
rg --sort path -l "pattern" | head -1
# WRONG — -c counts matching LINES, not total matches
rg -c "pattern"
# CORRECT — count every match occurrence
rg --count-matches "pattern"
# Find Ruby method definitions
rg "def (self\.)?authenticate" app/
# Find all usages of a constant
rg -w "UserPolicy" app/ spec/
# Search only Ruby files, show file list
rg -t ruby -l "has_many :projects"
# Find TODO/FIXME comments in non-test code
rg -t ruby -g "!spec/" "# (TODO|FIXME)"
# Search across ignored vendor/node_modules
rg -uu "lodash" --type js
# Find all files importing a specific module
rg "require.*auth_helper" -t ruby -l
# Multi-pattern OR search
rg -e "class.*Controller" -e "module.*Controller" app/controllers/
# Replace preview (no actual replace — rg doesn't modify files)
rg "old_method" --replace "new_method" src/ # prints substituted output only
. when possible-t type filters before broad patterns-P (PCRE2) unless you need it — measurably slower on large repos--pre (runs a process per file) — use --pre-glob to limit scope if needed--sort for large searches — it disables parallelism-l (files only) is faster than full content output when you just need file paths