searching-text
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseripgrep: Powerful, one-shot text search
ripgrep:强大的一次性文本搜索工具
Always invoke ripgrep skill for text search - do not execute bash commands directly.
文本搜索请始终调用ripgrep技能——不要直接执行bash命令。
Default Strategy
默认策略
Invoke ripgrep skill for fast text search with one-shot patterns. Use to get files, line numbers, and context in a single call.
-e 'pattern' -n -C 2This minimizes iterations and context usage. Always prefer getting line numbers and surrounding context over multiple search attempts.
Common workflow: ripgrep skill → other skills (fzf, bat, sd, analyzing-code-structure) for interactive selection, preview, or modification.
调用ripgrep技能,使用一次性匹配模式进行快速文本搜索。使用参数,单次调用即可获取文件、行号及上下文内容。
-e 'pattern' -n -C 2这能减少迭代次数和上下文占用。相比多次搜索尝试,应优先选择获取行号及周边上下文的方式。
常见工作流:ripgrep技能 → 其他技能(fzf、bat、sd、analyzing-code-structure),用于交互式选择、预览或修改。
Tool Selection
工具选择
Grep tool (built on ripgrep) - Use for structured searches:
- Basic pattern matching with structured output
- File type filtering with parameter
type - When special flags like ,
-F,-v, or pipe composition are not needed-w - Handles 95% of search needs
Bash(rg) - Use for one-shot searches needing special flags or composition:
- Fixed string search ()
-F - Invert match ()
-v - Word boundaries ()
-w - Context lines with patterns ()
-n -C 2 - Pipe composition (,
| head,| wc -l)| sort - Default choice for efficient one-shot results
Glob tool - Use for file name/path matching only (not content search)
Grep工具(基于ripgrep构建)- 用于结构化搜索:
- 带结构化输出的基础模式匹配
- 使用参数过滤文件类型
type - 不需要、
-F、-v等特殊标志或管道组合时使用-w - 可满足95%的搜索需求
Bash(rg) - 用于需要特殊标志或组合的一次性搜索:
- 固定字符串搜索()
-F - 反向匹配()
-v - 单词边界匹配()
-w - 带上下文的模式匹配()
-n -C 2 - 管道组合(、
| head、| wc -l)| sort - 高效一次性搜索的默认选择
Glob工具 - 仅用于文件名/路径匹配(不用于内容搜索)
When to Load Detailed Reference
何时加载详细参考文档
Load ripgrep guide when needing:
- One-shot search pattern templates
- Effective flag combinations for complex searches
- Pipe composition patterns
- File type filters reference (flags)
-t - Performance optimization for large result sets
- Pattern syntax examples
- Translation between Grep tool and rg commands
The guide focuses on practical patterns for getting targeted results in minimal calls.
当需要以下内容时,加载ripgrep指南:
- 一次性搜索模式模板
- 复杂搜索的有效标志组合
- 管道组合模式
- 文件类型过滤器参考(标志)
-t - 大结果集的性能优化
- 模式语法示例
- Grep工具与rg命令的对应转换
该指南专注于实用模式,帮助你通过最少的调用获取目标结果。
Pipeline Combinations
管道组合示例
- rg | fzf: Interactive selection from search results
- rg | sd: Batch replacements on search results
- rg | xargs: Execute commands on matched files
- rg | fzf:从搜索结果中进行交互式选择
- rg | sd:对搜索结果进行批量替换
- rg | xargs:对匹配的文件执行命令
Skill Combinations
技能组合
For Discovery Phase
发现阶段
- fd → ripgrep: Find files of specific type, then search within them
- extracting-code-structure → ripgrep: Understand structure, then search for specific patterns
- jq/yq → ripgrep: Extract field values, then search for their usage
- fd → ripgrep:查找特定类型的文件,然后在其中进行搜索
- extracting-code-structure → ripgrep:理解代码结构后,搜索特定模式
- jq/yq → ripgrep:提取字段值,然后搜索其使用场景
For Analysis Phase
分析阶段
- ripgrep → fzf: Interactive selection from search matches
- ripgrep → bat: View matched files with syntax highlighting
- ripgrep → ast-grep: After finding text patterns, apply structural changes
- ripgrep → fzf:从搜索匹配结果中进行交互式选择
- ripgrep → bat:查看带语法高亮的匹配文件
- ripgrep → ast-grep:找到文本模式后,应用结构化修改
For Refactoring Phase
重构阶段
- ripgrep → sd: Replace found patterns with new content
- ripgrep → xargs: Execute commands on all matching files
- ripgrep → tokei: Get statistics for files containing specific patterns
- ripgrep → analyzing-code-structure: After finding text patterns, apply structural changes
- ripgrep → sd:将找到的模式替换为新内容
- ripgrep → xargs:对所有匹配文件执行命令
- ripgrep → tokei:获取包含特定模式的文件统计信息
- ripgrep → analyzing-code-structure:找到文本模式后,应用结构化修改
Integration Examples
集成示例
bash
undefinedbash
undefinedFind and edit all references to a function
查找并编辑所有引用某个函数的位置
rg "functionName" -l | fzf --multi --preview="bat --color=always --highlight-line $(rg -n "functionName" {} | head -1 | cut -d: -f2) {}" | xargs vim
rg "functionName" -l | fzf --multi --preview="bat --color=always --highlight-line $(rg -n "functionName" {} | head -1 | cut -d: -f2) {}" | xargs vim
Find TODOs and create summary
查找TODO并生成摘要
rg "TODO|FIXME" -n | fzf --multi --preview="bat --color=always --highlight-line {2} {1}"
rg "TODO|FIXME" -n | fzf --multi --preview="bat --color=always --highlight-line {2} {1}"
undefined