用ripgrep进行快速搜索的方法

1,725 阅读10分钟

在这篇文章中,我想向你介绍ripgrep,一个聪明而快速的命令行搜索工具,我发现自己在编程时一直在使用它。 ripgrep递归搜索目录中的regex模式,并输出它找到的所有匹配结果。

为什么是ripgrep?

那么,是什么让ripgrep如此伟大?毕竟,现在已经有很多其他的搜索工具了,比如grepack或者The Silver Searcher。对我来说,它可以归结为以下几个原因。

  • ripgrep很聪明。它在开箱时就选择了合理的默认值。我喜欢这样。例如,ripgrep尊重.gitignore ,默认跳过匹配的文件和目录。它还忽略了二进制文件,跳过了隐藏的文件和目录,并且不遵循符号链接。
  • ripgrep很快速。事实上,它非常快。我已经向它扔了几十万个文件,没有遇到任何性能问题。查看ripgrep比{grep, ag, git grep, ucg, pt, sift}更快的详细分析和各种性能基准。

ripgrep还完全支持Unicode,可以搜索压缩文件,并可以选择让你切换其regex引擎以使用PCRE2正则表达式

安装

如果你正在使用Homebrew,你可以运行以下命令来安装ripgrep。

$ brew install ripgrep

如果你使用的是不同的软件包管理器,你可以在GitHub上的README.md中找到一份全面的安装说明。

The Basics

ripgrep可执行文件的名称是rg 。在其最基本的形式下,一个简单的搜索可以是这样的。

$ rg '// TODO'

这个命令将递归地搜索当前目录(及其子目录)中的所有文件,以寻找字符串// TODO ,并输出找到的匹配文件。如果我在prettier版本库src目录下运行这个命令,输出结果是这样的。

$ rg '// TODO'
language-css/parser-postcss.js
521:  // TODO: Remove this hack when this issue is fixed:

language-markdown/parser-markdown.js
121:    // TODO: Delete this in 2.0

language-handlebars/parser-glimmer.js
32:      // TODO: `locStart` and `locEnd` should return a number offset

common/util-shared.js
42:  mapDoc, // TODO: remove in 2.0, we already exposed it in docUtils

language-js/utils.js
239:// TODO: This is a bad hack and we need a better way to distinguish between

language-html/utils.js
80:  // TODO: handle non-text children in <pre>

common/internal-plugins.js
91:      // TODO: switch these to just `postcss` and use `language` instead.
134:      // TODO: Delete this in 2.0

language-html/constants.evaluate.js
21:  // TODO: send PR to upstream

language-js/printer-estree.js
5:// TODO(azz): anything that imports from main shouldn't be in a `language-*` dir.

匹配的文件是按文件名分组的。对于每个匹配项,ripgrep都会打印出行号,并突出显示匹配的子串。

经常使用的选项

在本文的剩余部分,我将介绍几个ripgrep选项,我发现自己在编程时经常使用这些选项来执行各种搜索任务。我使用prettier仓库来演示不同的选项以及它们的效果。

请随意克隆版本库并跟随我。

$ git clone https://github.com/prettier/prettier.git
$ cd prettier

另外,除非另有说明,我从src目录中运行所有命令。

$ cd src

没有选项

让我们从不使用任何选项来运行ripgrep开始。默认行为可能已经做了你想要的。在这里,我正在搜索当前工作目录下的字符串// TODO

$ rg '// TODO'
language-css/parser-postcss.js
521:  // TODO: Remove this hack when this issue is fixed:

language-markdown/parser-markdown.js
121:    // TODO: Delete this in 2.0

language-handlebars/parser-glimmer.js
32:      // TODO: `locStart` and `locEnd` should return a number offset

common/util-shared.js
42:  mapDoc, // TODO: remove in 2.0, we already exposed it in docUtils

language-js/utils.js
239:// TODO: This is a bad hack and we need a better way to distinguish between

language-html/utils.js
80:  // TODO: handle non-text children in <pre>

common/internal-plugins.js
91:      // TODO: switch these to just `postcss` and use `language` instead.
134:      // TODO: Delete this in 2.0

language-html/constants.evaluate.js
21:  // TODO: send PR to upstream

language-js/printer-estree.js
5:// TODO(azz): anything that imports from main shouldn't be in a `language-*` dir.

我们可以看到所有匹配的内容,按文件名分组,有行号和突出显示的匹配子串。如果你想在一堆文件和目录中快速找到一个指定的字符串,这可能已经足够了。

文件与匹配的文件

有时,你对看到匹配项本身并不感兴趣,而是对包含至少一个匹配项的所有文件的路径感兴趣。你可以使用--files-with-matches 选项,或者简称-l

$ rg -l '// TODO'
language-markdown/parser-markdown.js
common/util-shared.js
language-html/constants.evaluate.js
language-css/parser-postcss.js
common/internal-plugins.js
language-js/printer-estree.js
language-html/utils.js
language-js/utils.js
language-handlebars/parser-glimmer.js

请注意,ripgrep默认情况下不会按照特定的排序顺序来发送文件。这是出于性能的考虑。如果你想让文件路径列表按字母顺序排序,你可以使用--sort path 选项。

$ rg -l '// TODO' --sort path
common/internal-plugins.js
common/util-shared.js
language-css/parser-postcss.js
language-handlebars/parser-glimmer.js
language-html/constants.evaluate.js
language-html/utils.js
language-js/printer-estree.js
language-js/utils.js
language-markdown/parser-markdown.js

请注意,使用--sort path 选项会使ripgrep中的所有并行功能失效。除非你要搜索大量的文件,否则你可能不会注意到性能上的差别。

-l 标志对于将ripgrep的输出管道到另一个程序并对匹配的文件进行额外的操作特别有用。例如,你可以用ripgrep找到所有与字符串@format 匹配的文件,并使用prettier 可执行文件用Prettier格式化它们。

$ rg -l '@format' | xargs prettier --write

没有匹配的文件

有时,你可能对那些确实包含匹配的文件不感兴趣,而是对那些没有匹配的文件感兴趣。--files-without-match 选项正是输出这些文件。与--files-with-matches 选项不同,--files-without-match 选项没有一个简短的别名。

下面的命令列出了所有不包含任何字符串的文件var,let, 或const 。这些JavaScript文件不包含任何局部变量的声明。

$ rg --files-without-match '\b(var|let|const)\b'
language-yaml/pragma.js
language-graphql/pragma.js
document/index.js
utils/get-last.js
language-js/preprocess.js
common/internal-plugins.js
common/third-party.js
utils/arrayify.js
language-html/pragma.js
common/errors.js
language-html/clean.js

同样,我们可以通过使用--sort path 选项对文件列表进行排序。

$ rg --files-without-match '\b(var|let|const)\b' --sort path
common/errors.js
common/internal-plugins.js
common/third-party.js
document/index.js
language-graphql/pragma.js
language-html/clean.js
language-html/pragma.js
language-js/preprocess.js
language-yaml/pragma.js
utils/arrayify.js
utils/get-last.js

请注意,我们在搜索模式中使用了几个正则表达式的特征。

  • \b 匹配一个词的边界。这样,字符串 就不会与 模式相匹配。delete let
  • | 表示一个交替。模式 匹配任何与模式 , , 或 匹配的字符串。var|let|const var let const

ripgrep默认会将搜索模式作为正则表达式来处理;不需要指定其他标志来将搜索模式变成正则表达式。

倒置匹配

有时,你可能对所有匹配给定模式的行感兴趣,而不是那些匹配的行。ripgrep让我们使用--invert-match (或简称-v )标志来显示这些行。

时不时地,我想对我在某次 Git 提交中修改的所有代码行进行理智检查。当运行一个改变了成百上千个文件的codemod时,这一点尤其有用。在这种情况下,我希望看到一个经过分类和去掉重复的所有修改行的列表。下面是我使用的命令。

git show | rg '^[-+]' | rg -v '^[-+]{3}' | sort | uniq

对于Prettier版本库中的6daa7e199e2d71cee66f5ebee3b2efe4648d7b99的提交,这是输出。

+      - "patch-release"
-      - patch-release

如果我去掉管道中的rg -v '^[-+]{3}' 位,输出将包括文件名,这不是我想要的。

+      - "patch-release"
+++ b/.github/workflows/dev-test.yml
+++ b/.github/workflows/lint.yml
+++ b/.github/workflows/prod-test.yml
-      - patch-release
--- a/.github/workflows/dev-test.yml
--- a/.github/workflows/lint.yml
--- a/.github/workflows/prod-test.yml

通过管道将第一次搜索的输出通过rg -v '^[-+]{3}' ,我排除了所有以三个正负开头的行,在最后给我一个干净的输出。

固定的字符串

通常情况下,ripgrep将每个搜索模式默认为正则表达式,这很有用。我们在上一节中已经看到了我们如何使用模式var|let|const ,使用交替的方式搜索几个字符串,而且不需要额外的标志来告诉ripgrep将模式解释为正则表达式而不是固定的字符串。

然而,如果我们想搜索一个不是格式良好的正则表达式的字符串,我们会得到一个错误。

$ rg '?.'
regex parse error:
    ?.
    ^
error: repetition operator missing expression

在上面的例子中,我们对模式?. 的搜索失败了,因为这个模式是错误的。在正则表达式中,? 字符表示一个重复操作符,它使前面的表达式成为可选项。它必须跟在一个表达式后面,而在这里它并没有这样做。

我们可以告诉ripgrep,我们希望它把搜索字符串解释为一个固定的字符串,而不是正则表达式模式。所有在正则表达式中具有特殊含义的字符(例如:$,?,|, ...)将被逐字匹配。我们需要用来打开这种行为的标志被称为--fixed-strings ,或简称-F

$ rg -F '?.'
language-js/printer-estree.js
4763:    return "?.";

现在,搜索已经成功了,我们得到了所有与字符串?. 匹配的结果,并且是逐字逐句的。

围绕匹配的上下文

有时,只看到匹配的行本身,而没有任何前面或后面的行,可能缺乏上下文。再以搜索// TODO 为例。

$ rg '// TODO'
language-css/parser-postcss.js
521:  // TODO: Remove this hack when this issue is fixed:

common/util-shared.js
42:  mapDoc, // TODO: remove in 2.0, we already exposed it in docUtils

common/internal-plugins.js
91:      // TODO: switch these to just `postcss` and use `language` instead.
134:      // TODO: Delete this in 2.0

language-markdown/parser-markdown.js
121:    // TODO: Delete this in 2.0

language-handlebars/parser-glimmer.js
32:      // TODO: `locStart` and `locEnd` should return a number offset

language-js/utils.js
239:// TODO: This is a bad hack and we need a better way to distinguish between

language-js/printer-estree.js
5:// TODO(azz): anything that imports from main shouldn't be in a `language-*` dir.

language-html/constants.evaluate.js
21:  // TODO: send PR to upstream

language-html/utils.js
80:  // TODO: handle non-text children in <pre>

如果我们能看到每个// TODO 注释后面的几行,以了解每个注释所指的代码,这不是很有帮助吗?事实证明,ripgrep可以做到这一点。我们可以指定--context 选项(或简称-C ),并传递一个参数N ,让ripgrep显示每个匹配行前后的N 行。

$ rg '// TODO' -C 2
language-css/parser-postcss.js
519-  }
520-
521:  // TODO: Remove this hack when this issue is fixed:
522-  // https://github.com/shellscape/postcss-less/issues/88
523-  const LessParser = require("postcss-less/dist/less-parser");

language-markdown/parser-markdown.js
119-  parsers: {
120-    remark: markdownParser,
121:    // TODO: Delete this in 2.0
122-    markdown: markdownParser,
123-    mdx: mdxParser

common/util-shared.js
40-  isPreviousLineEmpty,
41-  getNextNonSpaceNonCommentCharacterIndex,
42:  mapDoc, // TODO: remove in 2.0, we already exposed it in docUtils
43-  makeString: util.makeString,
44-  addLeadingComment: util.addLeadingComment,

common/internal-plugins.js
89-  {
90-    parsers: {
91:      // TODO: switch these to just `postcss` and use `language` instead.
92-      get css() {
93-        return eval("require")("../language-css/parser-postcss").parsers.css;
--
132-          .remark;
133-      },
134:      // TODO: Delete this in 2.0
135-      get markdown() {
136-        return eval("require")("../language-markdown/parser-markdown").parsers

language-js/utils.js
237-}
238-
239:// TODO: This is a bad hack and we need a better way to distinguish between
240-// arrow functions and otherwise
241-function isFunctionNotation(node, options) {

language-handlebars/parser-glimmer.js
30-      parse,
31-      astFormat: "glimmer",
32:      // TODO: `locStart` and `locEnd` should return a number offset
33-      // https://prettier.io/docs/en/plugins.html#parsers
34-      // but we need access to the original text to use

language-html/constants.evaluate.js
19-
20-const CSS_DISPLAY_TAGS = Object.assign({}, getCssStyleTags("display"), {
21:  // TODO: send PR to upstream
22-  button: "inline-block",
23-

language-html/utils.js
78-  }
79-
80:  // TODO: handle non-text children in <pre>
81-  if (
82-    isPreLikeNode(node) &&

language-js/printer-estree.js
3-const assert = require("assert");
4-
5:// TODO(azz): anything that imports from main shouldn't be in a `language-*` dir.
6-const comments = require("../main/comments");
7-const {

现在,我们可以看到每个// TODO 注释前后的两行,给我们一些更多的背景,而不需要打开这些文件。

如果你想单独控制匹配行前后的行数,你可以分别使用--before-context--after-context 选项,或者简称-B-A 。例如,这里是所有// TODO 的注释,后面是三行。

$ rg '// TODO' -A 3
language-markdown/parser-markdown.js
121:    // TODO: Delete this in 2.0
122-    markdown: markdownParser,
123-    mdx: mdxParser
124-  }

common/util-shared.js
42:  mapDoc, // TODO: remove in 2.0, we already exposed it in docUtils
43-  makeString: util.makeString,
44-  addLeadingComment: util.addLeadingComment,
45-  addDanglingComment: util.addDanglingComment,

common/internal-plugins.js
91:      // TODO: switch these to just `postcss` and use `language` instead.
92-      get css() {
93-        return eval("require")("../language-css/parser-postcss").parsers.css;
94-      },
--
134:      // TODO: Delete this in 2.0
135-      get markdown() {
136-        return eval("require")("../language-markdown/parser-markdown").parsers
137-          .remark;

language-handlebars/parser-glimmer.js
32:      // TODO: `locStart` and `locEnd` should return a number offset
33-      // https://prettier.io/docs/en/plugins.html#parsers
34-      // but we need access to the original text to use
35-      // `loc.start` and `loc.end` objects to calculate the offset

language-js/utils.js
239:// TODO: This is a bad hack and we need a better way to distinguish between
240-// arrow functions and otherwise
241-function isFunctionNotation(node, options) {
242-  return isGetterOrSetter(node) || sameLocStart(node, node.value, options);

language-js/printer-estree.js
5:// TODO(azz): anything that imports from main shouldn't be in a `language-*` dir.
6-const comments = require("../main/comments");
7-const {
8-  getParentExportDeclaration,

language-css/parser-postcss.js
521:  // TODO: Remove this hack when this issue is fixed:
522-  // https://github.com/shellscape/postcss-less/issues/88
523-  const LessParser = require("postcss-less/dist/less-parser");
524-  LessParser.prototype.atrule = function() {

language-html/constants.evaluate.js
21:  // TODO: send PR to upstream
22-  button: "inline-block",
23-
24-  // special cases for some css display=none elements

language-html/utils.js
80:  // TODO: handle non-text children in <pre>
81-  if (
82-    isPreLikeNode(node) &&
83-    node.children.some(

只有特定的文件类型

--type 选项,或简称为-t ,让你把搜索限制在特定类型的文件上。为了看看这个选项是如何工作的,让我们从src目录上移一级,进入 prettier 仓库的根目录。

$ cd ..

让我们确认一下当前的工作目录。

$ pwd
/Users/marius/code/prettier

好了,现在我们准备好了。我们可以只在JavaScript文件上运行搜索@format

$ rg -t js '@format'
src/language-yaml/pragma.js
12:  return `# @format\n\n${text}`;

src/language-graphql/pragma.js
8:  return "# @format\n\n" + text;

src/language-css/clean.js
35:     * @format

src/language-html/pragma.js
8:  return "<!-- @format -->\n\n" + text.replace(/^\s*\n/, "");

src/main/core-options.js
110:    description: "Insert @format pragma into file's first docblock comment.",
234:      Require either '@prettier' or '@format' to be present in the file's first docblock comment

tests/insert-pragma/js/module-with-pragma.js
5: * @format

tests/require-pragma/js/module-with-pragma.js
3: * @format

或者我们可以只在Markdown文件中搜索。

$ rg -t md '@format'
docs/cli.md
101:Valid pragmas are `@prettier` and `@format`.
105:Insert a `@format` pragma to the top of formatted files when pragma is absent. Works well when used in tandem with `--require-pragma`.

docs/options.md
258: * @format
270:Prettier can insert a special @format marker at the top of files specifying that the file has been formatted with prettier. This works well when used in tandem with the `--require-pragma` option. If there is already a docblock at the top of the file then this option will add a newline to it with the @format marker.

website/blog/2017-09-15-1.7.0.md
108: * @format
187:- [**Add option to require @prettier or @format pragma**](https://github.com/prettier/prettier/pull/2772) by [@wbinnssmith](https://github.com/wbinnssmith)

website/blog/2017-05-03-1.3.0.md
25:- When pretty-printing a file, add `@format` to the first block comment like `@flow`.
26:- Have a lint rule with autofix that checks if the file is correctly pretty printed when `@format` is present.
29:- Update the default code templates to add `@format` to the header.
30:- When you run code formatting via cmd-shift-c inside of Nuclide, automatically insert the `@format` header.
31:- Disable all the stylistic rules like max-len when `@format` is in the header.
34:- When pushing a new release of prettier, also run it through all the files with `@format` in order to avoid getting warnings afterwards.
35:- Add tracking for the number of files with `@format` over time.

website/blog/2017-11-07-1.8.0.md
136:#### Add option to insert `@format` to first docblock if absent ([#2865](https://github.com/prettier/prettier/pull/2865)) by [@samouri](https://github.com/samouri)
138:In 1.7, we added an option called `--require-pragma` to require files contain an `/** @format */` pragma to be formatted. In order to add this pragma to a large set of files you can now use [`--insert-pragma`](https://prettier.io/docs/en/cli.html#insert-pragma) flag.

website/blog/2018-02-26-1.11.0.md
814: * @format
820: * @format

website/versioned_docs/version-stable/cli.md
102:Valid pragmas are `@prettier` and `@format`.
106:Insert a `@format` pragma to the top of formatted files when pragma is absent. Works well when used in tandem with `--require-pragma`.

website/versioned_docs/version-stable/options.md
259: * @format
271:Prettier can insert a special @format marker at the top of files specifying that the file has been formatted with prettier. This works well when used in tandem with the `--require-pragma` option. If there is already a docblock at the top of the file then this option will add a newline to it with the @format marker.

tests/markdown/real-world-case.md
292:Valid pragmas are `@prettier` and `@format`.
695: * @format

tests/require-pragma/markdown/with-pragma-in-multiline.md
6:  @format

注意,类型指定符jsmd 本身不是文件名的扩展名。类型指定符代表一组被认为是该类型的文件名扩展名。

  • js 代表扩展名**.js*,*.jsx,和**.vue*
  • md 代表扩展名**.markdown*、*.md*.mdown和**.mkdn*

你可以通过运行rg --type-list 命令,调出支持的类型指定器和相应的文件名扩展名的完整列表。

使用Glob

有时,使用--type (或简称-t )选项可能无法充分控制在搜索中包括哪些文件。在这些情况下,你可以使用--glob (或简称-g )选项。ripgrep将只搜索路径与指定的glob匹配的文件。

例如,你可以只在那些名字以 "parser-"开头的JavaScript文件中搜索// TODO 注释。

$ rg -g 'parser-*.js' '// TODO'
language-markdown/parser-markdown.js
121:    // TODO: Delete this in 2.0

language-handlebars/parser-glimmer.js
32:      // TODO: `locStart` and `locEnd` should return a number offset

language-css/parser-postcss.js
521:  // TODO: Remove this hack when this issue is fixed:

显示帮助页面

最后,如果你忘记了某个特定的选项叫什么,或者你想看看还有哪些选项可用,ripgrep提供了两种不同级别的帮助。

  • rg -h: 简短的描述,有一个浓缩的布局
  • rg --help:带有详细解释的长描述

下面是ripgrep 12.0.0在运行rg -h 命令时打印的内容。

ripgrep 12.0.0
Andrew Gallant <jamslam@gmail.com>

ripgrep (rg) recursively searches your current directory for a regex pattern.
By default, ripgrep will respect your .gitignore and automatically skip hidden
files/directories and binary files.

ripgrep's default regex engine uses finite automata and guarantees linear
time searching. Because of this, features like backreferences and arbitrary
look-around are not supported. However, if ripgrep is built with PCRE2, then
the --pcre2 flag can be used to enable backreferences and look-around.

ripgrep supports configuration files. Set RIPGREP_CONFIG_PATH to a
configuration file. The file can specify one shell argument per line. Lines
starting with '#' are ignored. For more details, see the man page or the
README.

ripgrep will automatically detect if stdin exists and search stdin for a regex
pattern, e.g. 'ls | rg foo'. In some environments, stdin may exist when it
shouldn't. To turn off stdin detection explicitly specify the directory to
search, e.g. 'rg foo ./'.

Tip: to disable all smart filtering and make ripgrep behave a bit more like
classical grep, use 'rg -uuu'.

Project home page: https://github.com/BurntSushi/ripgrep

Use -h for short descriptions and --help for more details.

USAGE:
    rg [OPTIONS] PATTERN [PATH ...]
    rg [OPTIONS] [-e PATTERN ...] [-f PATTERNFILE ...] [PATH ...]
    rg [OPTIONS] --files [PATH ...]
    rg [OPTIONS] --type-list
    command | rg [OPTIONS] PATTERN

ARGS:
    <PATTERN>    A regular expression used for searching.
    <PATH>...    A file or directory to search.

OPTIONS:
    -A, --after-context <NUM>               Show NUM lines after each match.
        --auto-hybrid-regex                 Dynamically use PCRE2 if necessary.
    -B, --before-context <NUM>              Show NUM lines before each match.
        --binary                            Search binary files.
        --block-buffered                    Force block buffering.
    -b, --byte-offset                       Print the 0-based byte offset for each matching line.
    -s, --case-sensitive                    Search case sensitively (default).
        --color <WHEN>                      Controls when to use color.
        --colors <COLOR_SPEC>...            Configure color settings and styles.
        --column                            Show column numbers.
    -C, --context <NUM>                     Show NUM lines before and after each match.
        --context-separator <SEPARATOR>     Set the context separator string.
    -c, --count                             Only show the count of matching lines for each file.
        --count-matches                     Only show the count of individual matches for each file.
        --crlf                              Support CRLF line terminators (useful on Windows).
        --debug                             Show debug messages.
        --dfa-size-limit <NUM+SUFFIX?>      The upper size limit of the regex DFA.
    -E, --encoding <ENCODING>               Specify the text encoding of files to search.
        --engine <ENGINE>                   Specify which regexp engine to use. [default: default]
    -f, --file <PATTERNFILE>...             Search for patterns from the given file.
        --files                             Print each file that would be searched.
    -l, --files-with-matches                Only print the paths with at least one match.
        --files-without-match               Only print the paths that contain zero matches.
    -F, --fixed-strings                     Treat the pattern as a literal string.
    -L, --follow                            Follow symbolic links.
    -g, --glob <GLOB>...                    Include or exclude files.
        --glob-case-insensitive             Process all glob patterns case insensitively.
    -h, --help                              Prints help information. Use --help for more details.
        --heading                           Print matches grouped by each file.
        --hidden                            Search hidden files and directories.
        --iglob <GLOB>...                   Include or exclude files case insensitively.
    -i, --ignore-case                       Case insensitive search.
        --ignore-file <PATH>...             Specify additional ignore files.
        --ignore-file-case-insensitive      Process ignore files case insensitively.
        --include-zero                      Include files with zero matches in summary
    -v, --invert-match                      Invert matching.
        --json                              Show search results in a JSON Lines format.
        --line-buffered                     Force line buffering.
    -n, --line-number                       Show line numbers.
    -x, --line-regexp                       Only show matches surrounded by line boundaries.
    -M, --max-columns <NUM>                 Don't print lines longer than this limit.
        --max-columns-preview               Print a preview for lines exceeding the limit.
    -m, --max-count <NUM>                   Limit the number of matches.
        --max-depth <NUM>                   Descend at most NUM directories.
        --max-filesize <NUM+SUFFIX?>        Ignore files larger than NUM in size.
        --mmap                              Search using memory maps when possible.
    -U, --multiline                         Enable matching across multiple lines.
        --multiline-dotall                  Make '.' match new lines when multiline is enabled.
        --no-config                         Never read configuration files.
    -I, --no-filename                       Never print the file path with the matched lines.
        --no-heading                        Don't group matches by each file.
        --no-ignore                         Don't respect ignore files.
        --no-ignore-dot                     Don't respect .ignore files.
        --no-ignore-exclude                 Don't respect local exclusion files.
        --no-ignore-files                   Don't respect --ignore-file arguments.
        --no-ignore-global                  Don't respect global ignore files.
        --no-ignore-messages                Suppress gitignore parse error messages.
        --no-ignore-parent                  Don't respect ignore files in parent directories.
        --no-ignore-vcs                     Don't respect VCS ignore files.
    -N, --no-line-number                    Suppress line numbers.
        --no-messages                       Suppress some error messages.
        --no-mmap                           Never use memory maps.
        --no-pcre2-unicode                  Disable Unicode mode for PCRE2 matching.
        --no-require-git                    Do not require a git repository to use gitignores.
        --no-unicode                        Disable Unicode mode.
    -0, --null                              Print a NUL byte after file paths.
        --null-data                         Use NUL as a line terminator instead of \n.
        --one-file-system                   Do not descend into directories on other file systems.
    -o, --only-matching                     Print only matches parts of a line.
        --passthru                          Print both matching and non-matching lines.
        --path-separator <SEPARATOR>        Set the path separator.
    -P, --pcre2                             Enable PCRE2 matching.
        --pcre2-version                     Print the version of PCRE2 that ripgrep uses.
        --pre <COMMAND>                     search outputs of COMMAND FILE for each FILE
        --pre-glob <GLOB>...                Include or exclude files from a preprocessing command.
    -p, --pretty                            Alias for --color always --heading --line-number.
    -q, --quiet                             Do not print anything to stdout.
        --regex-size-limit <NUM+SUFFIX?>    The upper size limit of the compiled regex.
    -e, --regexp <PATTERN>...               A pattern to search for.
    -r, --replace <REPLACEMENT_TEXT>        Replace matches with the given text.
    -z, --search-zip                        Search in compressed files.
    -S, --smart-case                        Smart case search.
        --sort <SORTBY>                     Sort results in ascending order. Implies --threads=1.
        --sortr <SORTBY>                    Sort results in descending order. Implies --threads=1.
        --stats                             Print statistics about this ripgrep search.
    -a, --text                              Search binary files as if they were text.
    -j, --threads <NUM>                     The approximate number of threads to use.
        --trim                              Trim prefixed whitespace from matches.
    -t, --type <TYPE>...                    Only search files matching TYPE.
        --type-add <TYPE_SPEC>...           Add a new glob for a file type.
        --type-clear <TYPE>...              Clear globs for a file type.
        --type-list                         Show all supported file types.
    -T, --type-not <TYPE>...                Do not search files matching TYPE.
    -u, --unrestricted                      Reduce the level of "smart" searching.
    -V, --version                           Prints version information
        --vimgrep                           Show results in vim compatible format.
    -H, --with-filename                     Print the file path with the matched lines.
    -w, --word-regexp                       Only show matches surrounded by word boundaries.