# ripgrep
ripgrep (`rg`) is a line-oriented search tool that recursively searches directories for a regex pattern. It's written in [[Rust]] by Andrew Galloway (BurntSushi) and is designed as a faster alternative to `grep`, `ack`, ...
## Key features
- **Fast**: uses Rust's regex engine, parallelism, and smart directory traversal for high performance
- **Respects `.gitignore`**: automatically skips files matched by `.gitignore`, `.ignore`, and `.rgignore` rules
- **Unicode support**: searches UTF-8, UTF-16, latin-1, GBK, EUC-JP, Shift_JIS, and more
- **Compressed file search**: can search within gzip, bzip2, xz, LZ4, LZMA, Brotli, Zstandard files
- **File type filtering**: built-in support for filtering by file type (`--type`, `-t`)
- **Replacement support**: `--replace` for search-and-replace workflows
- **Multiline matching**: `--multiline` (`-U`) for patterns spanning multiple lines
- **PCRE2 support**: optional PCRE2 engine for lookaround and backreferences (`--pcre2`, `-P`)
## Installation
```sh
# Debian/Ubuntu
sudo apt install ripgrep
# Arch
pacman -S ripgrep
# macOS
brew install ripgrep
# Cargo
cargo install ripgrep
# npm (cross-platform)
npm install -g @aspect-build/ripgrep
```
## Common usage
```sh
# Basic search
rg "pattern" path/
# Case-insensitive
rg -i "pattern"
# Search specific file types
rg -t py "import"
# Show context lines (before/after/both)
rg -B 2 -A 2 "pattern"
rg -C 3 "pattern"
# Show only filenames
rg -l "pattern"
# Count matches per file
rg -c "pattern"
# Fixed string (no regex)
rg -F "literal string"
# Glob filtering
rg --glob "*.ts" "pattern"
rg -g "!*.min.js" "pattern"
# Multiline
rg -U "start.*\nend"
# Replace (preview)
rg "old" --replace "new"
# Include hidden/ignored files
rg --hidden --no-ignore "pattern"
```
## Configuration
ripgrep reads configuration from a file pointed to by the `RIPGREP_CONFIG_PATH` environment variable:
```sh
export RIPGREP_CONFIG_PATH="$HOME/.ripgreprc"
```
Example `.ripgreprc`:
```
--smart-case
--hidden
--glob=!.git/
--max-columns=200
```
## Integration with other tools
- **[[Claude Code]]**: uses ripgrep as its built-in `Grep` tool; listed as a pre-requisite for installation
- **[[Visual Studio Code (VSCode)]]**: uses ripgrep for workspace search
- **[[fzf]]**: commonly paired for fuzzy file finding (`rg --files | fzf`)
- **[[Neovim]]**: telescope.nvim and other plugins use ripgrep as a search backend
## References
- Source code: https://github.com/BurntSushi/ripgrep
- User guide: https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md
## Related
- [[Command Line Interface (CLI)]]
- [[Claude Code]]
- [[Rust]]
- [[grep]]
- [[fzf]]
- [[Neovim]]
- [[Vim]]
- [[Vi]]
- [[Nano]]