Ripgrep Code Search: Lightning-Fast Terminal Hacks

User avatar placeholder
Written by Tamzid Ahmed

June 1, 2026

When you need to find code across thousands of files, traditional grep can feel painfully slow. Enter ripgrep (rg), a modern command-line tool built for speed and developer ergonomics. Master the art of ripgrep code search to find code faster than ever.

Why ripgrep is the ultimate code search tool

Unlike traditional tools, ripgrep is engineered specifically for developers. It uses Rust’s memory safety and SIMD instructions to deliver blazing-fast performance—typically 5-10x faster than grep in real-world codebases. Its intelligent defaults automatically respect .gitignore files and skip binary files, eliminating manual configuration for most projects.

Installing ripgrep on any system

Getting started is simple across all platforms:

  • macOS: brew install ripgrep
  • Linux: sudo apt install ripgrep (Debian/Ubuntu) or use your distro’s package manager
  • Windows: Install via Scoop (scoop install ripgrep) or Chocolatey (choco install ripgrep)

For other systems, check the official ripgrep documentation.

Basic ripgrep usage for code search

Simple searches and directory recursion

Run rg "function_name" in your project root to recursively search all files. Unlike grep, it automatically ignores hidden files and version control directories by default. For example, searching for "handleRequest" in a Node.js project skips node_modules without extra flags.

Ignoring files and directories

Use --ignore to exclude specific paths:

  • rg --ignore "*.log" "error" — searches while ignoring log files
  • rg --ignore "test/" "api" — excludes test directories

For persistent ignores, create a .rgignore file in your project root—ripgrep reads this automatically.

Advanced ripgrep flags for precision

Regex patterns and case sensitivity

Enable regex matching with --regexp (or -G for filename patterns). Control case sensitivity:

  • rg --case-sensitive "API" — strict case matching
  • rg --ignore-case "error" — case-insensitive search

Use -w for whole-word matches to avoid partial matches like “api” in “appliance”.

Context and line numbers

Show surrounding lines with -A (after) and -B (before):

  • rg -B 2 "main()" — shows 2 lines before each match
  • rg -C 3 "function" — shows 3 lines before and after

Line numbers appear by default; disable with --no-number.

Key ripgrep flags for code search

Here’s a quick reference for the most useful flags:

  • –type: Search only specific file types (e.g., rg --type js "useState" for JavaScript files)
  • –hidden: Include hidden files (default is to skip them)
  • –files: List all searchable files without searching content
  • –vimgrep: Output in Vim-compatible format for quick editing

Practical examples: real-world code search scenarios

Find all React component files containing useEffect across a large codebase:

rg --type ts "useEffect" --glob "*.tsx"

Search for deprecated functions while ignoring test files:

rg --ignore "*test*" "deprecated"

For cross-repository searches, combine with find for precise control:

find . -name "*.py" -exec rg "async" {} ;

Integrating ripgrep into your workflow

Pipe ripgrep results to other tools for enhanced productivity. For example, combine with fzf for interactive selection:

rg "search_term" | fzf

Use it in Vim with :Rg via plugins like vim-ripgrep, or integrate with IDEs like VS Code for instant in-editor search.

Conclusion

Mastering ripgrep code search transforms how you navigate codebases. Start using it today to save hours of developer time—simply run rg "your_query" and experience the speed difference instantly.

Leave a Comment