1.1 KiB
1.1 KiB
name, description, category, tool_id
| name | description | category | tool_id |
|---|---|---|---|
| ripgrep | 极速代码搜索工具(rg)- grep的现代化替代品 | essential | EXT-RG-001 |
ripgrep (rg) ⭐⭐⭐⭐⭐
用途
极速代码搜索,默认递归搜索且遵守.gitignore
安装
macOS
brew install ripgrep
Ubuntu/Debian
sudo apt-get install ripgrep
配置
# 添加到 ~/.bashrc
alias grep='rg'
使用
# 搜索Python文件中的TODO
rg "TODO" -g "*.py"
# 显示上下文(3行)
rg -A 3 -B 3 "def function_name" app.py
# 统计匹配数
rg --count "import"
# 搜索并打开文件
rg "TODO" --files-with-matches | fzf | xargs bat
常用选项
-i-- 忽略大小写-g-- 文件模式匹配(glob)-A NUM-- 显示匹配后NUM行-B NUM-- 显示匹配前NUM行-C NUM-- 显示匹配前后各NUM行--count-- 统计匹配数--files-with-matches-- 只显示包含匹配的文件名
技巧
# 搜索并替换(预览)
rg "old_function" -S | fzf
# 指定编码
rg --encoding utf8 "pattern"
# 与fzf集成
rg "" --files-with-matches | fzf --preview 'rg --color=always "" {}'