rg pattern | Search current directory |
rg pattern path/ | Search specific path |
rg pattern file.txt | Search in file |
rg "multi word" | Search phrase |
rg -i pattern | Case insensitive |
rg -w pattern | Whole word match |
rg -x pattern | Whole line match |
rg -n pattern | Show line numbers (default) |
rg -N pattern | Hide line numbers |
rg -l pattern | Show only filenames |
rg -c pattern | Count matches per file |
rg --count-matches pattern | Count all matches |
rg -o pattern | Show only matched text |
rg -v pattern | Invert match |
rg -C 3 pattern | 3 lines before and after |
rg -B 2 pattern | 2 lines before |
rg -A 2 pattern | 2 lines after |
rg --context-separator="---" -C 2 pattern | Custom separator |
rg -t py pattern | Search Python files |
rg -t js -t ts pattern | Multiple file types |
rg -T py pattern | Exclude Python files |
rg --type-list | List file types |
rg --type-add "web:*.{html,css,js}" -t web pattern | Custom type |
rg -g "*.js" pattern | Include glob |
rg -g "!*.min.js" pattern | Exclude glob |
rg -g "src/**/*.ts" pattern | Recursive glob |
rg -g "!node_modules" pattern | Exclude directory |
rg --hidden pattern | Include hidden files |
rg --no-ignore pattern | Don't respect .gitignore |
rg -u pattern | Unrestricted (--no-ignore) |
rg -uu pattern | More unrestricted (+hidden) |
rg -uuu pattern | All files (including binary) |
rg --max-depth 2 pattern | Limit directory depth |
rg -L pattern | Follow symlinks |
rg "\bword\b" | Word boundary |
rg "^start" | Line start |
rg "end$" | Line end |
rg "a.*b" | Any characters between |
rg "a.+b" | One or more between |
rg "colou?r" | Optional character |
rg "[aeiou]" | Character class |
rg "[0-9]+" | One or more digits |
rg "(foo|bar)" | Alternation |
rg -F "literal." | Fixed string (no regex) |
rg -P "(?<=foo)bar" | PCRE2 regex |
rg -U "foo\nbar" | Multiline search |
rg -s pattern | Case sensitive (smart) |
rg -S pattern | Smart case |
rg -r "replacement" pattern | Replace matches |
rg -r "$1" "(\w+)" | Capture group |
rg -r "${1}_${2}" "(\w+)-(\w+)" | Multiple captures |
rg --passthru -r "new" "old" | Show all lines with replacement |
rg --color=always pattern | less -R | Color with less |
rg --no-heading pattern | No file headings |
rg --heading pattern | Group by file |
rg --vimgrep pattern | Vim-compatible output |
rg --json pattern | JSON output |
rg --stats pattern | Show statistics |
rg --sort path pattern | Sort by path |
rg --sort modified pattern | Sort by modified time |
rg --sort accessed pattern | Sort by access time |
rg --sort created pattern | Sort by creation time |
rg --sortr path pattern | Reverse sort |
# ~/.ripgreprc
# Set with RIPGREP_CONFIG_PATH
# Smart case by default
--smart-case
# Include hidden files
--hidden
# Exclude directories
--glob=!.git
--glob=!node_modules
--glob=!vendor
--glob=!*.min.js
# Max columns for long lines
--max-columns=200
# Show context
--context=2
# Custom type
--type-add=web:*.{html,css,js,ts} # .rgignore or .ignore
# Same syntax as .gitignore
node_modules/
dist/
build/
*.log
*.min.js
.env
*.pyc
__pycache__/ rg -t py "import" | wc -l | Count Python imports |
rg -l TODO | xargs code | Open TODO files in VS Code |
rg -t js "console.log" -l | Find files with console.log |
rg -t py "def " -c | sort -t: -k2 -rn | Files by function count |
rg "TODO|FIXME|HACK" --stats | Find code annotations |
rg -e "pattern1" -e "pattern2" | Multiple patterns (OR) |
rg "func" | rg "error" | Multiple patterns (AND) |
rg "\b(var|let)\b" -t js | Find var/let in JS |