These are the most commonly used switches I use in rg.
Command | Description |
---|---|
rg pattern |
Search pattern in current dir recursively |
rg pattern utils.py |
Search in a single file utils.py |
rg pattern src/ |
Search in dir src/ recursively |
rg '^We' test.txt |
Regex searching support (lines starting with We) |
rg -F '(test)' |
Search literally, i.e., without using regular expression |
rg -i pattern |
Search pattern and ignore case (case-insensitive search) |
rg -S pattern |
Smart case search (match case of pattern) |
rg pattern -g '*.py' |
File globbing (search in certain files), can be used multiple times |
rg pattern -g '!*.py' |
Negative file globing (do not search in certain files) |
rg pattern -g '!dir1/' |
Exclude dir1 |
rg pattern -t py |
Search pattern in Python file. To list the supported filetypes, use rg --type-list |
rg pattern -T py |
Do not search pattern in Python file type |
rg -l pattern |
Only show file names containing pattern (Do not show the lines) |
rg --files-without-match pattern |
Show files not containing pattern |
rg -v pattern |
Inverse search (search lines not containing pattern) |
rg -w pattern |
Search surrounded by word boundaries. |
rg -A NUM |
Show NUM lines before each match. |
rg -B NUM |
Show NUM lines before each match. |
rg -C NUM |
Show NUM lines before and after each match. |