Gatlin.io Icon
Image of Austin Gatlin's face
March 10, 2022 (last updated March 23, 2022)

Ripgrep Cheatsheet

Ripgrep is a fast search tool. The command line syntax is rg [expression] [path]. There is an introductory guide in the repo.

Regex Syntax

The expression is a Rust Regex. To be safe you should wrap the expression in quotes, ' or ", 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

Flags

  • -l or --files-with-matches only show file paths

    Print the paths with at least one match and suppress match contents. This overrides --files-without-match.

  • --no-messages suppress errors

    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.

Commands

  • 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 doSomething:

    vim $(rg -l 'function doSomething\(' ./)