Ripgrep is a fast search tool. The command line syntax is
rg [expression] [path]. There is an introductory guide in the repo.
The expression is a Rust Regex. To be safe you should wrap the expression in quotes,
", though for simple queries you can omit them. For example, if you are searching for content containing
^[ in zsh:
rg ^[ ./ # -> zsh: bad pattern: ^[ rg '^[' ./ # -> regex parse error: ... rg \^\[ ./ # -> regex parse error: ... rg '\^\[' ./ # -> success
--contextshow lines before and after each match
rg -C 10, will show 10 lines before and after a line match. This is the same as writing
-B 10 for before-context and
-A 10 for after-context.
--files-with-matchesonly show file paths
Print the paths with at least one match and suppress match contents. This overrides --files-without-match.
Suppress all error messages related to opening and reading files. Error messages related to the syntax of the pattern given are still shown. This flag can be disabled with the --messages flag.
rg -l --no-messages [query] [path]will give you a simple list of file paths whose contents contain the query.
One cool thing you can do with this command is open files in a text editor. For example, to open the file containing the function
vim $(rg -l 'function doSomething\(' ./)