Ripgrep (rg) Documentation
A comprehensive guide to mastering ripgrep — the fastest code-search tool available. Written in Rust, rg is built for modern codebases: it is parallel, .gitignore-aware, regex-capable, and ergonomic by default.
Mental model: Think of
rgasgrepwith the best defaults already set — no more--exclude-dir=node_modules, no more-rn, no more case complaints.
Curriculum
1. Introduction
- What is Ripgrep? — Why it exists and what makes it different.
- Installing rg — apt, brew, cargo, and Docker.
2. Core Syntax
- Basic Search — Pattern, path, and the implicit defaults.
- Multiple Patterns — OR logic,
-e, and piping to a secondrg.
3. Smart Defaults
- Gitignore Awareness — What rg ignores and why.
- Hidden and Ignored Files —
-u,-uu,-uuuoverride ladder.
4. Regex & Patterns
- Regex Engine — Rust regex vs PCRE2 (
-P). - Anchors, Classes, and Quantifiers — Practical patterns for logs and code.
- Fixed Strings — When to use
-Ffor speed and safety.
5. File & Type Filtering
- File Type Filters —
-t py,-T json, and custom types. - Glob Patterns —
-g "*.conf"and negation.
6. Output & Context
- Context Lines —
-A,-B,-Cfor stack traces. - Formatting Flags —
-l,-c,-n,--json,--vimgrep.
7. Performance & Tuning
- Parallel Search — Thread control and I/O tuning.
- Memory Maps and Large Files —
--mmap,--no-mmap.
8. Real World Workflows
- Code Refactoring — Finding then replacing across projects.
- Log Analysis — Extracting IPs, errors, and JSON fields.
- Editor Integration — VSCode, Vim, fzf pipelines.
9. Troubleshooting
- No Results — Common Causes — Diagnosing hidden/ignored mismatches.
- Encoding and Binary Issues —
-a,--encoding, and detection.
10. Cheatsheet
- Ripgrep Cheatsheet — All flags, quick reference tables, and pipelines.
Quick start
# Install
cargo install ripgrep # or: brew install ripgrep / apt install ripgrep
# Search any project instantly
rg "TODO" # search cwd, respects .gitignore
rg -t py "def process" # only Python files
rg -l "API_KEY" /etc # just file names
rg -C 3 "panic" logs/ # 3 lines of context