Ripgrep
ripgrep (rg)
ripgrep, often called rg, is a fast command-line search tool for text inside files.
Think of it as grep on steroids—it searches recursively, is super fast, and respects .gitignore by default.
Why Developers Use ripgrep
- Quickly search through codebases for strings or patterns
- Faster than
grep, especially for large projects - Respects
.gitignore, so you don’t get spam from ignored files - Integrates nicely with fzf or other terminal tools for workflow
Basic Usage
- Searches for
"search_term"in current directory and subdirectories - Example: Find all occurrences of
TODOin a project:
Common Options
| Option | Description | Example |
|---|---|---|
-i |
Ignore case | rg -i todo |
-v |
Invert match | rg -v debug |
-w |
Match whole words | rg -w function |
-n |
Show line numbers | rg -n TODO |
--files |
List all files (like fd) |
rg --files |
-g |
Include/exclude patterns | rg -g '*.py' TODO |
Examples
- Search for
mainin Python files only:
- Search ignoring case:
- Show line numbers for matches:
- Combine with fzf for interactive search:
- Search through all project files interactively.
Advanced Use
- Preview matches with
bat:
- Use in scripts to automatically find and replace text.
- Integrates with Neovim/LazyVim for fast in-editor search.