Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ $ rg fast README.md -r FAST
[snip]
```

Here, `-r` is short for `--replace`, not recursive search. ripgrep already
searches directories recursively by default. For example, `rg -rn PATTERN`
replaces each match with `n`; use `rg -n PATTERN` to show line numbers without
replacing matches.

In essence, the `--replace` flag applies *only* to the matching portion of text
in the output. If you instead wanted to replace an entire line of text, then
you need to include the entire line in your match. For example:
Expand Down
5 changes: 5 additions & 0 deletions crates/core/flags/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6371,6 +6371,11 @@ impl Flag for Replace {
Replaces every match with the text given when printing results. Neither this
flag nor any other ripgrep flag will modify your files.
.sp
Unlike grep, ripgrep searches directories recursively by default. The
\fB-r\fP flag is short for \fB--replace\fP, not recursive search. For example,
\fBrg -rn PATTERN\fP replaces each match with \fBn\fP. To show line numbers
without replacing matches, use \fBrg -n PATTERN\fP.
.sp
Capture group indices (e.g., \fB$\fP\fI5\fP) and names (e.g., \fB$\fP\fIfoo\fP)
are supported in the replacement string. Capture group indices are numbered
based on the position of the opening parenthesis of the group, where the
Expand Down
Loading