@builder.io/dev-tools-windows-x64 1.19.9 → 1.19.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1046 @@
1
+ ## FAQ
2
+
3
+ * [Does ripgrep support configuration files?](#config)
4
+ * [What's changed in ripgrep recently?](#changelog)
5
+ * [When is the next release?](#release)
6
+ * [Does ripgrep have a man page?](#manpage)
7
+ * [Does ripgrep have support for shell auto-completion?](#complete)
8
+ * [How can I get results in a consistent order?](#order)
9
+ * [How do I search files that aren't UTF-8?](#encoding)
10
+ * [How do I search compressed files?](#compressed)
11
+ * [How do I search over multiple lines?](#multiline)
12
+ * [How do I use lookaround and/or backreferences?](#fancy)
13
+ * [How do I configure ripgrep's colors?](#colors)
14
+ * [How do I enable true colors on Windows?](#truecolors-windows)
15
+ * [How do I stop ripgrep from messing up colors when I kill it?](#stop-ripgrep)
16
+ * [Why does using a leading `/` on Windows fail?](#because-cygwin)
17
+ * [How do I get around the regex size limit?](#size-limit)
18
+ * [How do I make the `-f/--file` flag faster?](#dfa-size)
19
+ * [How do I make the output look like The Silver Searcher's output?](#silver-searcher-output)
20
+ * [Why does ripgrep get slower when I enabled PCRE2 regexes?](#pcre2-slow)
21
+ * [When I run `rg`, why does it execute some other command?](#rg-other-cmd)
22
+ * [How do I create an alias for ripgrep on Windows?](#rg-alias-windows)
23
+ * [How do I create a PowerShell profile?](#powershell-profile)
24
+ * [How do I pipe non-ASCII content to ripgrep on Windows?](#pipe-non-ascii-windows)
25
+ * [How can I search and replace with ripgrep?](#search-and-replace)
26
+ * [How is ripgrep licensed?](#license)
27
+ * [Can ripgrep replace grep?](#posix4ever)
28
+ * [What does the "rip" in ripgrep mean?](#intentcountsforsomething)
29
+ * [How can I donate to ripgrep or its maintainers?](#donations)
30
+
31
+
32
+ <h3 name="config">
33
+ Does ripgrep support configuration files?
34
+ </h3>
35
+
36
+ Yes. See the
37
+ [guide's section on configuration files](GUIDE.md#configuration-file).
38
+
39
+
40
+ <h3 name="changelog">
41
+ What's changed in ripgrep recently?
42
+ </h3>
43
+
44
+ Please consult ripgrep's [CHANGELOG](CHANGELOG.md).
45
+
46
+
47
+ <h3 name="release">
48
+ When is the next release?
49
+ </h3>
50
+
51
+ ripgrep is a project whose contributors are volunteers. A release schedule
52
+ adds undue stress to said volunteers. Therefore, releases are made on a best
53
+ effort basis and no dates **will ever be given**.
54
+
55
+ An exception to this _can be_ high impact bugs. If a ripgrep release contains
56
+ a significant regression, then there will generally be a strong push to get a
57
+ patch release out with a fix. However, no promises are made.
58
+
59
+
60
+ <h3 name="manpage">
61
+ Does ripgrep have a man page?
62
+ </h3>
63
+
64
+ Yes. If you installed ripgrep through a package manager on a Unix system, then
65
+ it would have ideally been installed for you in the proper location. In which
66
+ case, `man rg` should just work.
67
+
68
+ Otherwise, you can ask ripgrep to generate the man page:
69
+
70
+ ```
71
+ $ mkdir -p man/man1
72
+ $ rg --generate man > man/man1/rg.1
73
+ $ MANPATH="$PWD/man" man rg
74
+ ```
75
+
76
+ Or, if your version of `man` supports the `-l/--local-file` flag, then this
77
+ will suffice:
78
+
79
+ ```
80
+ $ rg --generate man | man -l -
81
+ ```
82
+
83
+ Note that the man page's documentation for options is equivalent to the output
84
+ shown in `rg --help`. To see more condensed documentation (one line per flag),
85
+ run `rg -h`.
86
+
87
+ The man page is also included in all
88
+ [ripgrep binary releases](https://github.com/BurntSushi/ripgrep/releases).
89
+
90
+
91
+ <h3 name="complete">
92
+ Does ripgrep have support for shell auto-completion?
93
+ </h3>
94
+
95
+ Yes! If you installed ripgrep through a package manager on a Unix system, then
96
+ the shell completion files included in the release archive should have been
97
+ installed for you automatically. If not, you can generate completes using
98
+ ripgrep's command line interface.
99
+
100
+ For **bash**:
101
+
102
+ ```
103
+ $ dir="$XDG_CONFIG_HOME/bash_completion"
104
+ $ mkdir -p "$dir"
105
+ $ rg --generate complete-bash > "$dir/rg.bash"
106
+ ```
107
+
108
+ For **fish**:
109
+
110
+ ```
111
+ $ dir="$XDG_CONFIG_HOME/fish/completions"
112
+ $ mkdir -p "$dir"
113
+ $ rg --generate complete-fish > "$dir/rg.fish"
114
+ ```
115
+
116
+ For **zsh**:
117
+
118
+ ```
119
+ $ dir="$HOME/.zsh-complete"
120
+ $ mkdir -p "$dir"
121
+ $ rg --generate complete-zsh > "$dir/_rg"
122
+ ```
123
+
124
+ For **PowerShell**, create the completions:
125
+
126
+ ```
127
+ $ rg --generate complete-powershell > _rg.ps1
128
+ ```
129
+
130
+ And then add `. _rg.ps1` to your PowerShell
131
+ [profile](https://technet.microsoft.com/en-us/library/bb613488(v=vs.85).aspx)
132
+ (note the leading period). If the `_rg.ps1` file is not on your `PATH`, do
133
+ `. /path/to/_rg.ps1` instead.
134
+
135
+
136
+ <h3 name="order">
137
+ How can I get results in a consistent order?
138
+ </h3>
139
+
140
+ By default, ripgrep uses parallelism to execute its search because this makes
141
+ the search much faster on most modern systems. This in turn means that ripgrep
142
+ has a non-deterministic aspect to it, since the interleaving of threads during
143
+ the execution of the program is itself non-deterministic. This has the effect
144
+ of printing results in a somewhat arbitrary order, and this order can change
145
+ from run to run of ripgrep.
146
+
147
+ The only way to make the order of results consistent is to ask ripgrep to
148
+ sort the output. Currently, this will disable all parallelism. (On smaller
149
+ repositories, you might not notice much of a performance difference!) You
150
+ can achieve this with the `--sort path` flag.
151
+
152
+ There is more discussion on this topic here:
153
+ https://github.com/BurntSushi/ripgrep/issues/152
154
+
155
+
156
+ <h3 name="encoding">
157
+ How do I search files that aren't UTF-8?
158
+ </h3>
159
+
160
+ See the [guide's section on file encoding](GUIDE.md#file-encoding).
161
+
162
+
163
+ <h3 name="compressed">
164
+ How do I search compressed files?
165
+ </h3>
166
+
167
+ ripgrep's `-z/--search-zip` flag will cause it to search compressed files
168
+ automatically. Currently, this supports gzip, bzip2, xz, lzma, lz4, Brotli and
169
+ Zstd. Each of these requires the corresponding `gzip`, `bzip2`, `xz`,
170
+ `lz4`, `brotli` and `zstd` binaries to be installed on your system. (That is,
171
+ ripgrep does decompression by shelling out to another process.)
172
+
173
+ ripgrep currently does not search archive formats, so `*.tar.gz` files, for
174
+ example, are skipped.
175
+
176
+
177
+ <h3 name="multiline">
178
+ How do I search over multiple lines?
179
+ </h3>
180
+
181
+ The `-U/--multiline` flag enables ripgrep to report results that span over
182
+ multiple lines.
183
+
184
+
185
+ <h3 name="fancy">
186
+ How do I use lookaround and/or backreferences?
187
+ </h3>
188
+
189
+ ripgrep's default regex engine does not support lookaround or backreferences.
190
+ This is primarily because the default regex engine is implemented using finite
191
+ state machines in order to guarantee a linear worst case time complexity on all
192
+ inputs. Backreferences are not possible to implement in this paradigm, and
193
+ lookaround appears difficult to do efficiently.
194
+
195
+ However, ripgrep optionally supports using PCRE2 as the regex engine instead of
196
+ the default one based on finite state machines. You can enable PCRE2 with the
197
+ `-P/--pcre2` flag. For example, in the root of the ripgrep repo, you can easily
198
+ find all palindromes:
199
+
200
+ ```
201
+ $ rg -P '(\w{10})\1'
202
+ tests/misc.rs
203
+ 483: cmd.arg("--max-filesize").arg("44444444444444444444");
204
+ globset/src/glob.rs
205
+ 1206: matches!(match7, "a*a*a*a*a*a*a*a*a", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
206
+ ```
207
+
208
+ If your version of ripgrep doesn't support PCRE2, then you'll get an error
209
+ message when you try to use the `-P/--pcre2` flag:
210
+
211
+ ```
212
+ $ rg -P '(\w{10})\1'
213
+ PCRE2 is not available in this build of ripgrep
214
+ ```
215
+
216
+ Most of the releases distributed by the ripgrep project here on GitHub will
217
+ come bundled with PCRE2 enabled. If you installed ripgrep through a different
218
+ means (like your system's package manager), then please reach out to the
219
+ maintainer of that package to see whether it's possible to enable the PCRE2
220
+ feature.
221
+
222
+
223
+ <h3 name="colors">
224
+ How do I configure ripgrep's colors?
225
+ </h3>
226
+
227
+ ripgrep has two flags related to colors:
228
+
229
+ * `--color` controls *when* to use colors.
230
+ * `--colors` controls *which* colors to use.
231
+
232
+ The `--color` flag accepts one of the following possible values: `never`,
233
+ `auto`, `always` or `ansi`. The `auto` value is the default and will cause
234
+ ripgrep to only enable colors when it is printing to a terminal. But if you
235
+ pipe ripgrep to a file or some other process, then it will suppress colors.
236
+
237
+ The `--colors` flag is a bit more complicated. The general format is:
238
+
239
+ ```
240
+ --colors '{type}:{attribute}:{value}'
241
+ ```
242
+
243
+ * `{type}` should be one of `path`, `line`, `column` or `match`. Each of these
244
+ correspond to the four different types of things that ripgrep will add color
245
+ to in its output. Select the type whose color you want to change.
246
+ * `{attribute}` should be one of `fg`, `bg` or `style`, corresponding to
247
+ foreground color, background color, or miscellaneous styling (such as whether
248
+ to bold the output or not).
249
+ * `{value}` is determined by the value of `{attribute}`. If
250
+ `{attribute}` is `style`, then `{value}` should be one of `nobold`,
251
+ `bold`, `nointense`, `intense`, `nounderline` or `underline`. If
252
+ `{attribute}` is `fg` or `bg`, then `{value}` should be a color.
253
+
254
+ A color is specified by either one of eight of English names, a single 256-bit
255
+ number or an RGB triple (with over 16 million possible values, or "true
256
+ color").
257
+
258
+ The color names are `red`, `blue`, `green`, `cyan`, `magenta`, `yellow`,
259
+ `white` or `black`.
260
+
261
+ A single 256-bit number is a value in the range 0-255 (inclusive). It can
262
+ either be in decimal format (e.g., `62`) or hexadecimal format (e.g., `0x3E`).
263
+
264
+ An RGB triple corresponds to three numbers (decimal or hexadecimal) separated
265
+ by commas.
266
+
267
+ As a special case, `--colors '{type}:none'` will clear all colors and styles
268
+ associated with `{type}`, which lets you start with a clean slate (instead of
269
+ building on top of ripgrep's default color settings).
270
+
271
+ Here's an example that makes highlights the matches with a nice blue background
272
+ with bolded white text:
273
+
274
+ ```
275
+ $ rg somepattern \
276
+ --colors 'match:none' \
277
+ --colors 'match:bg:0x33,0x66,0xFF' \
278
+ --colors 'match:fg:white' \
279
+ --colors 'match:style:bold'
280
+ ```
281
+
282
+ Colors are an ideal candidate to set in your
283
+ [configuration file](GUIDE.md#configuration-file). See the
284
+ [question on emulating The Silver Searcher's output style](#silver-searcher-output)
285
+ for an example specific to colors.
286
+
287
+
288
+ <h3 name="truecolors-windows">
289
+ How do I enable true colors on Windows?
290
+ </h3>
291
+
292
+ First, see the previous question's
293
+ [answer on configuring colors](#colors).
294
+
295
+ Secondly, coloring on Windows is a bit complicated. If you're using a terminal
296
+ like Cygwin, then it's likely true color support already works out of the box.
297
+ However, if you are using a normal Windows console (`cmd` or `PowerShell`) and
298
+ a version of Windows prior to 10, then there is no known way to get true
299
+ color support. If you are on Windows 10 and using a Windows console, then
300
+ true colors should work out of the box with one caveat: you might need to
301
+ clear ripgrep's default color settings first. That is, instead of this:
302
+
303
+ ```
304
+ $ rg somepattern --colors 'match:fg:0x33,0x66,0xFF'
305
+ ```
306
+
307
+ you should do this
308
+
309
+ ```
310
+ $ rg somepattern --colors 'match:none' --colors 'match:fg:0x33,0x66,0xFF'
311
+ ```
312
+
313
+ This is because ripgrep might set the default style for `match` to `bold`, and
314
+ it seems like Windows 10's VT100 support doesn't permit bold and true color
315
+ ANSI escapes to be used simultaneously. The work-around above will clear
316
+ ripgrep's default styling, allowing you to craft it exactly as desired.
317
+
318
+
319
+ <h3 name="stop-ripgrep">
320
+ How do I stop ripgrep from messing up colors when I kill it?
321
+ </h3>
322
+
323
+ Type in `color` in cmd.exe (Command Prompt) and `echo -ne "\033[0m"` on
324
+ Unix-like systems to restore your original foreground color.
325
+
326
+ In PowerShell, you can add the following code to your profile which will
327
+ restore the original foreground color when `Reset-ForegroundColor` is called.
328
+ Including the `Set-Alias` line will allow you to call it with simply `color`.
329
+
330
+ ```powershell
331
+ $OrigFgColor = $Host.UI.RawUI.ForegroundColor
332
+ function Reset-ForegroundColor {
333
+ $Host.UI.RawUI.ForegroundColor = $OrigFgColor
334
+ }
335
+ Set-Alias -Name color -Value Reset-ForegroundColor
336
+ ```
337
+
338
+ PR [#187](https://github.com/BurntSushi/ripgrep/pull/187) fixed this, and it
339
+ was later deprecated in
340
+ [#281](https://github.com/BurntSushi/ripgrep/issues/281). A full explanation is
341
+ available
342
+ [here](https://github.com/BurntSushi/ripgrep/issues/281#issuecomment-269093893).
343
+
344
+
345
+ <h3 name="because-cygwin">
346
+ Why does using a leading `/` on Windows fail?
347
+ </h3>
348
+
349
+ If you're using cygwin on Windows and try to search for a pattern beginning
350
+ with a `/`, then it's possible that cygwin is mangling that pattern without
351
+ your knowledge. For example, if you tried running `rg /foo` in a cygwin shell
352
+ on Windows, then cygwin might mistakenly perform path translation on `/foo`,
353
+ which would result in `rg C:/msys64/foo` being searched instead.
354
+
355
+ You can fix this in one of three ways:
356
+
357
+ 1. Stop using cygwin.
358
+ 2. Escape the leading slash with an additional slash. e.g., `rg //foo`.
359
+ 3. Temporarily disable path translation by setting `MSYS_NO_PATHCONV=1`. e.g.,
360
+ `MSYS_NO_PATHCONV=1 rg /foo`.
361
+
362
+ For more details, see https://github.com/BurntSushi/ripgrep/issues/1277
363
+
364
+
365
+ <h3 name="size-limit">
366
+ How do I get around the regex size limit?
367
+ </h3>
368
+
369
+ If you've given ripgrep a particularly large pattern (or a large number of
370
+ smaller patterns), then it is possible that it will fail to compile because it
371
+ hit a pre-set limit. For example:
372
+
373
+ ```
374
+ $ rg '\pL{1000}'
375
+ Compiled regex exceeds size limit of 10485760 bytes.
376
+ ```
377
+
378
+ (Note: `\pL{1000}` may look small, but `\pL` is the character class containing
379
+ all Unicode letters, which is quite large. *And* it's repeated 1000 times.)
380
+
381
+ In this case, you can work around by simply increasing the limit:
382
+
383
+ ```
384
+ $ rg '\pL{1000}' --regex-size-limit 1G
385
+ ```
386
+
387
+ Increasing the limit to 1GB does not necessarily mean that ripgrep will use
388
+ that much memory. The limit just says that it's allowed to (approximately) use
389
+ that much memory for constructing the regular expression.
390
+
391
+
392
+ <h3 name="dfa-size">
393
+ How do I make the <code>-f/--file</code> flag faster?
394
+ </h3>
395
+
396
+ The `-f/--file` permits one to give a file to ripgrep which contains a pattern
397
+ on each line. ripgrep will then report any line that matches any of the
398
+ patterns.
399
+
400
+ If this pattern file gets too big, then it is possible ripgrep will slow down
401
+ dramatically. *Typically* this is because an internal cache is too small, and
402
+ will cause ripgrep to spill over to a slower but more robust regular expression
403
+ engine. If this is indeed the problem, then it is possible to increase this
404
+ cache and regain speed. The cache can be controlled via the `--dfa-size-limit`
405
+ flag. For example, using `--dfa-size-limit 1G` will set the cache size to 1GB.
406
+ (Note that this doesn't mean ripgrep will use 1GB of memory automatically, but
407
+ it will allow the regex engine to if it needs to.)
408
+
409
+
410
+ <h3 name="silver-searcher-output">
411
+ How do I make the output look like The Silver Searcher's output?
412
+ </h3>
413
+
414
+ Use the `--colors` flag, like so:
415
+
416
+ ```
417
+ rg --colors line:fg:yellow \
418
+ --colors line:style:bold \
419
+ --colors path:fg:green \
420
+ --colors path:style:bold \
421
+ --colors match:fg:black \
422
+ --colors match:bg:yellow \
423
+ --colors match:style:nobold \
424
+ foo
425
+ ```
426
+
427
+ Alternatively, add your color configuration to your ripgrep config file (which
428
+ is activated by setting the `RIPGREP_CONFIG_PATH` environment variable to point
429
+ to your config file). For example:
430
+
431
+ ```
432
+ $ cat $HOME/.config/ripgrep/rc
433
+ --colors=line:fg:yellow
434
+ --colors=line:style:bold
435
+ --colors=path:fg:green
436
+ --colors=path:style:bold
437
+ --colors=match:fg:black
438
+ --colors=match:bg:yellow
439
+ --colors=match:style:nobold
440
+ $ RIPGREP_CONFIG_PATH=$HOME/.config/ripgrep/rc rg foo
441
+ ```
442
+
443
+
444
+ <h3 name="pcre2-slow">
445
+ Why does ripgrep get slower when I enable PCRE2 regexes?
446
+ </h3>
447
+
448
+ When you use the `--pcre2` (`-P` for short) flag, ripgrep will use the PCRE2
449
+ regex engine instead of the default. Both regex engines are quite fast,
450
+ but PCRE2 provides a number of additional features such as look-around and
451
+ backreferences that many enjoy using. This is largely because PCRE2 uses
452
+ a backtracking implementation where as the default regex engine uses a finite
453
+ automaton based implementation. The former provides the ability to add lots of
454
+ bells and whistles over the latter, but the latter executes with worst case
455
+ linear time complexity.
456
+
457
+ With that out of the way, if you've used `-P` with ripgrep, you may have
458
+ noticed that it can be slower. The reasons for why this is are quite complex,
459
+ and they are complex because the optimizations that ripgrep uses to implement
460
+ fast search are complex.
461
+
462
+ The task ripgrep has before it is somewhat simple; all it needs to do is search
463
+ a file for occurrences of some pattern and then print the lines containing
464
+ those occurrences. The problem lies in what is considered a valid match and how
465
+ exactly we read the bytes from a file.
466
+
467
+ In terms of what is considered a valid match, remember that ripgrep will only
468
+ report matches spanning a single line by default. The problem here is that
469
+ some patterns can match across multiple lines, and ripgrep needs to prevent
470
+ that from happening. For example, `foo\sbar` will match `foo\nbar`. The most
471
+ obvious way to achieve this is to read the data from a file, and then apply
472
+ the pattern search to that data for each line. The problem with this approach
473
+ is that it can be quite slow; it would be much faster to let the pattern
474
+ search across as much data as possible. It's faster because it gets rid of the
475
+ overhead of finding the boundaries of every line, and also because it gets rid
476
+ of the overhead of starting and stopping the pattern search for every single
477
+ line. (This is operating under the general assumption that matching lines are
478
+ much rarer than non-matching lines.)
479
+
480
+ It turns out that we can use the faster approach by applying a very simple
481
+ restriction to the pattern: *statically prevent* the pattern from matching
482
+ through a `\n` character. Namely, when given a pattern like `foo\sbar`,
483
+ ripgrep will remove `\n` from the `\s` character class automatically. In some
484
+ cases, a simple removal is not so easy. For example, ripgrep will return an
485
+ error when your pattern includes a `\n` literal:
486
+
487
+ ```
488
+ $ rg '\n'
489
+ the literal '"\n"' is not allowed in a regex
490
+ ```
491
+
492
+ So what does this have to do with PCRE2? Well, ripgrep's default regex engine
493
+ exposes APIs for doing syntactic analysis on the pattern in a way that makes
494
+ it quite easy to strip `\n` from the pattern (or otherwise detect it and report
495
+ an error if stripping isn't possible). PCRE2 seemingly does not provide a
496
+ similar API, so ripgrep does not do any stripping when PCRE2 is enabled. This
497
+ forces ripgrep to use the "slow" search strategy of searching each line
498
+ individually.
499
+
500
+ OK, so if enabling PCRE2 slows down the default method of searching because it
501
+ forces matches to be limited to a single line, then why is PCRE2 also sometimes
502
+ slower when performing multiline searches? Well, that's because there are
503
+ *multiple* reasons why using PCRE2 in ripgrep can be slower than the default
504
+ regex engine. This time, blame PCRE2's Unicode support, which ripgrep enables
505
+ by default. In particular, PCRE2 cannot simultaneously enable Unicode support
506
+ and search arbitrary data. That is, when PCRE2's Unicode support is enabled,
507
+ the data **must** be valid UTF-8 (to do otherwise is to invoke undefined
508
+ behavior). This is in contrast to ripgrep's default regex engine, which can
509
+ enable Unicode support and still search arbitrary data. ripgrep's default
510
+ regex engine simply won't match invalid UTF-8 for a pattern that can otherwise
511
+ only match valid UTF-8. Why doesn't PCRE2 do the same? This author isn't
512
+ familiar with its internals, so we can't comment on it here.
513
+
514
+ The bottom line here is that we can't enable PCRE2's Unicode support without
515
+ simultaneously incurring a performance penalty for ensuring that we are
516
+ searching valid UTF-8. In particular, ripgrep will transcode the contents
517
+ of each file to UTF-8 while replacing invalid UTF-8 data with the Unicode
518
+ replacement codepoint. ripgrep then disables PCRE2's own internal UTF-8
519
+ checking, since we've guaranteed the data we hand it will be valid UTF-8. The
520
+ reason why ripgrep takes this approach is because if we do hand PCRE2 invalid
521
+ UTF-8, then it will report a match error if it comes across an invalid UTF-8
522
+ sequence. This is not good news for ripgrep, since it will stop it from
523
+ searching the rest of the file, and will also print potentially undesirable
524
+ error messages to users.
525
+
526
+ All right, the above is a lot of information to swallow if you aren't already
527
+ familiar with ripgrep internals. Let's make this concrete with some examples.
528
+ First, let's get some data big enough to magnify the performance differences:
529
+
530
+ ```
531
+ $ curl -O 'https://burntsushi.net/stuff/subtitles2016-sample.gz'
532
+ $ gzip -d subtitles2016-sample
533
+ $ md5sum subtitles2016-sample
534
+ e3cb796a20bbc602fbfd6bb43bda45f5 subtitles2016-sample
535
+ ```
536
+
537
+ To search this data, we will use the pattern `^\w{42}$`, which contains exactly
538
+ one hit in the file and has no literals. Having no literals is important,
539
+ because it ensures that the regex engine won't use literal optimizations to
540
+ speed up the search. In other words, it lets us reason coherently about the
541
+ actual task that the regex engine is performing.
542
+
543
+ Let's now walk through a few examples in light of the information above. First,
544
+ let's consider the default search using ripgrep's default regex engine and
545
+ then the same search with PCRE2:
546
+
547
+ ```
548
+ $ time rg '^\w{42}$' subtitles2016-sample
549
+ 21225780:EverymajordevelopmentinthehistoryofAmerica
550
+
551
+ real 0m1.783s
552
+ user 0m1.731s
553
+ sys 0m0.051s
554
+
555
+ $ time rg -P '^\w{42}$' subtitles2016-sample
556
+ 21225780:EverymajordevelopmentinthehistoryofAmerica
557
+
558
+ real 0m2.458s
559
+ user 0m2.419s
560
+ sys 0m0.038s
561
+ ```
562
+
563
+ In this particular example, both pattern searches are using a Unicode aware
564
+ `\w` character class and both are counting lines in order to report line
565
+ numbers. The key difference here is that the first search will not search
566
+ line by line, but the second one will. We can observe which strategy ripgrep
567
+ uses by passing the `--trace` flag:
568
+
569
+ ```
570
+ $ rg '^\w{42}$' subtitles2016-sample --trace
571
+ [... snip ...]
572
+ TRACE|grep_searcher::searcher|grep-searcher/src/searcher/mod.rs:622: Some("subtitles2016-sample"): searching via memory map
573
+ TRACE|grep_searcher::searcher|grep-searcher/src/searcher/mod.rs:712: slice reader: searching via slice-by-line strategy
574
+ TRACE|grep_searcher::searcher::core|grep-searcher/src/searcher/core.rs:61: searcher core: will use fast line searcher
575
+ [... snip ...]
576
+
577
+ $ rg -P '^\w{42}$' subtitles2016-sample --trace
578
+ [... snip ...]
579
+ TRACE|grep_searcher::searcher|grep-searcher/src/searcher/mod.rs:622: Some("subtitles2016-sample"): searching via memory map
580
+ TRACE|grep_searcher::searcher|grep-searcher/src/searcher/mod.rs:705: slice reader: needs transcoding, using generic reader
581
+ TRACE|grep_searcher::searcher|grep-searcher/src/searcher/mod.rs:685: generic reader: searching via roll buffer strategy
582
+ TRACE|grep_searcher::searcher::core|grep-searcher/src/searcher/core.rs:63: searcher core: will use slow line searcher
583
+ [... snip ...]
584
+ ```
585
+
586
+ The first says it is using the "fast line searcher" where as the latter says
587
+ it is using the "slow line searcher." The latter also shows that we are
588
+ decoding the contents of the file, which also impacts performance.
589
+
590
+ Interestingly, in this case, the pattern does not match a `\n` and the file
591
+ we're searching is valid UTF-8, so neither the slow line-by-line search
592
+ strategy nor the decoding are necessary. We could fix the former issue with
593
+ better PCRE2 introspection APIs. We can actually fix the latter issue with
594
+ ripgrep's `--no-encoding` flag, which prevents the automatic UTF-8 decoding,
595
+ but will enable PCRE2's own UTF-8 validity checking. Unfortunately, it's slower
596
+ in my build of ripgrep:
597
+
598
+ ```
599
+ $ time rg -P '^\w{42}$' subtitles2016-sample --no-encoding
600
+ 21225780:EverymajordevelopmentinthehistoryofAmerica
601
+
602
+ real 0m3.074s
603
+ user 0m3.021s
604
+ sys 0m0.051s
605
+ ```
606
+
607
+ (Tip: use the `--trace` flag to verify that no decoding in ripgrep is
608
+ happening.)
609
+
610
+ A possible reason why PCRE2's UTF-8 checking is slower is because it might
611
+ not be better than the highly optimized UTF-8 checking routines found in the
612
+ [`encoding_rs`](https://github.com/hsivonen/encoding_rs) library, which is what
613
+ ripgrep uses for UTF-8 decoding. Moreover, my build of ripgrep enables
614
+ `encoding_rs`'s SIMD optimizations, which may be in play here.
615
+
616
+ Also, note that using the `--no-encoding` flag can cause PCRE2 to report
617
+ invalid UTF-8 errors, which causes ripgrep to stop searching the file:
618
+
619
+ ```
620
+ $ cat invalid-utf8
621
+ foobar
622
+
623
+ $ xxd invalid-utf8
624
+ 00000000: 666f 6fff 6261 720a foo.bar.
625
+
626
+ $ rg foo invalid-utf8
627
+ 1:foobar
628
+
629
+ $ rg -P foo invalid-utf8
630
+ 1:foo�bar
631
+
632
+ $ rg -P foo invalid-utf8 --no-encoding
633
+ invalid-utf8: PCRE2: error matching: UTF-8 error: illegal byte (0xfe or 0xff)
634
+ ```
635
+
636
+ All right, so at this point, you might think that we could remove the penalty
637
+ for line-by-line searching by enabling multiline search. After all, our
638
+ particular pattern can't match across multiple lines anyway, so we'll still get
639
+ the results we want. Let's try it:
640
+
641
+ ```
642
+ $ time rg -U '^\w{42}$' subtitles2016-sample
643
+ 21225780:EverymajordevelopmentinthehistoryofAmerica
644
+
645
+ real 0m1.803s
646
+ user 0m1.748s
647
+ sys 0m0.054s
648
+
649
+ $ time rg -P -U '^\w{42}$' subtitles2016-sample
650
+ 21225780:EverymajordevelopmentinthehistoryofAmerica
651
+
652
+ real 0m2.962s
653
+ user 0m2.246s
654
+ sys 0m0.713s
655
+ ```
656
+
657
+ Search times remain the same with the default regex engine, but the PCRE2
658
+ search gets _slower_. What happened? The secrets can be revealed with the
659
+ `--trace` flag once again. In the former case, ripgrep actually detects that
660
+ the pattern can't match across multiple lines, and so will fall back to the
661
+ "fast line search" strategy as with our search without `-U`.
662
+
663
+ However, for PCRE2, things are much worse. Namely, since Unicode mode is still
664
+ enabled, ripgrep is still going to decode UTF-8 to ensure that it hands only
665
+ valid UTF-8 to PCRE2. Unfortunately, one key downside of multiline search is
666
+ that ripgrep cannot do it incrementally. Since matches can be arbitrarily long,
667
+ ripgrep actually needs the entire file in memory at once. Normally, we can use
668
+ a memory map for this, but because we need to UTF-8 decode the file before
669
+ searching it, ripgrep winds up reading the entire contents of the file on to
670
+ the heap before executing a search. Owch.
671
+
672
+ OK, so Unicode is killing us here. The file we're searching is _mostly_ ASCII,
673
+ so maybe we're OK with missing some data. (Try `rg '[\w--\p{ascii}]'` to see
674
+ non-ASCII word characters that an ASCII-only `\w` character class would miss.)
675
+ We can disable Unicode in both searches, but this is done differently depending
676
+ on the regex engine we use:
677
+
678
+ ```
679
+ $ time rg '(?-u)^\w{42}$' subtitles2016-sample
680
+ 21225780:EverymajordevelopmentinthehistoryofAmerica
681
+
682
+ real 0m1.714s
683
+ user 0m1.669s
684
+ sys 0m0.044s
685
+
686
+ $ time rg -P '^\w{42}$' subtitles2016-sample --no-pcre2-unicode
687
+ 21225780:EverymajordevelopmentinthehistoryofAmerica
688
+
689
+ real 0m1.997s
690
+ user 0m1.958s
691
+ sys 0m0.037s
692
+ ```
693
+
694
+ For the most part, ripgrep's default regex engine performs about the same.
695
+ PCRE2 does improve a little bit, and is now almost as fast as the default
696
+ regex engine. If you look at the output of `--trace`, you'll see that ripgrep
697
+ will no longer perform UTF-8 decoding, but it does still use the slow
698
+ line-by-line searcher.
699
+
700
+ At this point, we can combine all of our insights above: let's try to get off
701
+ of the slow line-by-line searcher by enabling multiline mode, and let's stop
702
+ UTF-8 decoding by disabling Unicode support:
703
+
704
+ ```
705
+ $ time rg -U '(?-u)^\w{42}$' subtitles2016-sample
706
+ 21225780:EverymajordevelopmentinthehistoryofAmerica
707
+
708
+ real 0m1.714s
709
+ user 0m1.655s
710
+ sys 0m0.058s
711
+
712
+ $ time rg -P -U '^\w{42}$' subtitles2016-sample --no-pcre2-unicode
713
+ 21225780:EverymajordevelopmentinthehistoryofAmerica
714
+
715
+ real 0m1.121s
716
+ user 0m1.071s
717
+ sys 0m0.048s
718
+ ```
719
+
720
+ Ah, there's PCRE2's JIT shining! ripgrep's default regex engine once again
721
+ remains about the same, but PCRE2 no longer needs to search line-by-line and it
722
+ no longer needs to do any kind of UTF-8 checks. This allows the file to get
723
+ memory mapped and passed right through PCRE2's JIT at impressive speeds. (As
724
+ a brief and interesting historical note, the configuration of "memory map +
725
+ multiline + no-Unicode" is exactly the configuration used by The Silver
726
+ Searcher. This analysis perhaps sheds some reasoning as to why that
727
+ configuration is useful!)
728
+
729
+ In summary, if you want PCRE2 to go as fast as possible and you don't care
730
+ about Unicode and you don't care about matches possibly spanning across
731
+ multiple lines, then enable multiline mode with `-U` and disable PCRE2's
732
+ Unicode support with the `--no-pcre2-unicode` flag.
733
+
734
+ Caveat emptor: This author is not a PCRE2 expert, so there may be APIs that can
735
+ improve performance that the author missed. Similarly, there may be alternative
736
+ designs for a searching tool that are more amenable to how PCRE2 works.
737
+
738
+
739
+ <h3 name="rg-other-cmd">
740
+ When I run <code>rg</code>, why does it execute some other command?
741
+ </h3>
742
+
743
+ It's likely that you have a shell alias or even another tool called `rg` which
744
+ is interfering with ripgrep. Run `which rg` to see what it is.
745
+
746
+ (Notably, the Rails plug-in for
747
+ [Oh My Zsh](https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#rails) sets
748
+ up an `rg` alias for `rails generate`.)
749
+
750
+ Problems like this can be resolved in one of several ways:
751
+
752
+ * If you're using the OMZ Rails plug-in, disable it by editing the `plugins`
753
+ array in your zsh configuration.
754
+ * Temporarily bypass an existing `rg` alias by calling ripgrep as
755
+ `command rg`, `\rg`, or `'rg'`.
756
+ * Temporarily bypass an existing alias or another tool named `rg` by calling
757
+ ripgrep by its full path (e.g., `/usr/bin/rg` or `/usr/local/bin/rg`).
758
+ * Permanently disable an existing `rg` alias by adding `unalias rg` to the
759
+ bottom of your shell configuration file (e.g., `.bash_profile` or `.zshrc`).
760
+ * Give ripgrep its own alias that doesn't conflict with other tools/aliases by
761
+ adding a line like the following to the bottom of your shell configuration
762
+ file: `alias ripgrep='command rg'`.
763
+
764
+
765
+ <h3 name="rg-alias-windows">
766
+ How do I create an alias for ripgrep on Windows?
767
+ </h3>
768
+
769
+ Often you can find a need to make alias for commands you use a lot that set
770
+ certain flags. But PowerShell function aliases do not behave like your typical
771
+ linux shell alias. You always need to propagate arguments and `stdin` input.
772
+ But it cannot be done simply as
773
+ `function grep() { $input | rg.exe --hidden $args }`
774
+
775
+ Use below example as reference to how setup alias in PowerShell.
776
+
777
+ ```powershell
778
+ function grep {
779
+ $count = @($input).Count
780
+ $input.Reset()
781
+
782
+ if ($count) {
783
+ $input | rg.exe --hidden $args
784
+ }
785
+ else {
786
+ rg.exe --hidden $args
787
+ }
788
+ }
789
+ ```
790
+
791
+ PowerShell special variables:
792
+
793
+ * input - is powershell `stdin` object that allows you to access its content.
794
+ * args - is array of arguments passed to this function.
795
+
796
+ This alias checks whether there is `stdin` input and propagates only if there
797
+ is some lines. Otherwise empty `$input` will make powershell to trigger `rg` to
798
+ search empty `stdin`.
799
+
800
+
801
+ <h3 name="powershell-profile">
802
+ How do I create a PowerShell profile?
803
+ </h3>
804
+
805
+ To customize powershell on start-up, there is a special PowerShell script that
806
+ has to be created. In order to find its location, type `$profile`.
807
+ See
808
+ [Microsoft's documentation](https://technet.microsoft.com/en-us/library/bb613488(v=vs.85).aspx)
809
+ for more details.
810
+
811
+ Any PowerShell code in this file gets evaluated at the start of console. This
812
+ way you can have own aliases to be created at start.
813
+
814
+
815
+ <h3 name="pipe-non-ascii-windows">
816
+ How do I pipe non-ASCII content to ripgrep on Windows?
817
+ </h3>
818
+
819
+ When piping input into native executables in PowerShell, the encoding of the
820
+ input is controlled by the `$OutputEncoding` variable. By default, this is set
821
+ to US-ASCII, and any characters in the pipeline that don't have encodings in
822
+ US-ASCII are converted to `?` (question mark) characters.
823
+
824
+ To change this setting, set `$OutputEncoding` to a different encoding, as
825
+ represented by a .NET encoding object. Some common examples are below. The
826
+ value of this variable is reset when PowerShell restarts, so to make this
827
+ change take effect every time PowerShell is started add a line setting the
828
+ variable into your PowerShell profile.
829
+
830
+ Example `$OutputEncoding` settings:
831
+
832
+ * UTF-8 without BOM: `$OutputEncoding = [System.Text.UTF8Encoding]::new()`
833
+ * The console's output encoding:
834
+ `$OutputEncoding = [System.Console]::OutputEncoding`
835
+
836
+ If you continue to have encoding problems, you can also force the encoding
837
+ that the console will use for printing to UTF-8 with
838
+ `[System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8`. This
839
+ will also reset when PowerShell is restarted, so you can add that line
840
+ to your profile as well if you want to make the setting permanent.
841
+
842
+ <h3 name="search-and-replace">
843
+ How can I search and replace with ripgrep?
844
+ </h3>
845
+
846
+ Using ripgrep alone, you can't. ripgrep is a search tool that will never
847
+ touch your files. However, the output of ripgrep can be piped to other tools
848
+ that do modify files on disk. See
849
+ [this issue](https://github.com/BurntSushi/ripgrep/issues/74) for more
850
+ information.
851
+
852
+ sed is one such tool that can modify files on disk. sed can take a filename
853
+ and a substitution command to search and replace in the specified file.
854
+ Files containing matching patterns can be provided to sed using
855
+
856
+ ```
857
+ rg foo --files-with-matches
858
+ ```
859
+
860
+ The output of this command is a list of filenames that contain a match for
861
+ the `foo` pattern.
862
+
863
+ This list can be piped into `xargs`, which will split the filenames from
864
+ standard input into arguments for the command following xargs. You can use this
865
+ combination to pipe a list of filenames into sed for replacement. For example:
866
+
867
+ ```
868
+ rg foo --files-with-matches | xargs sed -i 's/foo/bar/g'
869
+ ```
870
+
871
+ will replace all instances of 'foo' with 'bar' in the files in which
872
+ ripgrep finds the foo pattern. The `-i` flag to sed indicates that you are
873
+ editing files in place, and `s/foo/bar/g` says that you are performing a
874
+ **s**ubstitution of the pattern `foo` for `bar`, and that you are doing this
875
+ substitution **g**lobally (all occurrences of the pattern in each file).
876
+
877
+ Note: the above command assumes that you are using GNU sed. If you are using
878
+ BSD sed (the default on macOS and FreeBSD) then you must modify the above
879
+ command to be the following:
880
+
881
+ ```
882
+ rg foo --files-with-matches | xargs sed -i '' 's/foo/bar/g'
883
+ ```
884
+
885
+ The `-i` flag in BSD sed requires a file extension to be given to make backups
886
+ for all modified files. Specifying the empty string prevents file backups from
887
+ being made.
888
+
889
+ Finally, if any of your file paths contain whitespace in them, then you might
890
+ need to delimit your file paths with a NUL terminator. This requires telling
891
+ ripgrep to output NUL bytes between each path, and telling xargs to read paths
892
+ delimited by NUL bytes:
893
+
894
+ ```
895
+ rg foo --files-with-matches -0 | xargs -0 sed -i 's/foo/bar/g'
896
+ ```
897
+
898
+ To learn more about sed, see the sed manual
899
+ [here](https://www.gnu.org/software/sed/manual/sed.html).
900
+
901
+ Additionally, Facebook has a tool called
902
+ [fastmod](https://github.com/facebookincubator/fastmod)
903
+ that uses some of the same libraries as ripgrep and might provide a more
904
+ ergonomic search-and-replace experience.
905
+
906
+
907
+ <h3 name="license">
908
+ How is ripgrep licensed?
909
+ </h3>
910
+
911
+ ripgrep is dual licensed under the
912
+ [Unlicense](https://unlicense.org/)
913
+ and MIT licenses. Specifically, you may use ripgrep under the terms of either
914
+ license.
915
+
916
+ The reason why ripgrep is dual licensed this way is two-fold:
917
+
918
+ 1. I, as ripgrep's author, would like to participate in a small bit of
919
+ ideological activism by promoting the Unlicense's goal: to disclaim
920
+ copyright monopoly interest.
921
+ 2. I, as ripgrep's author, would like as many people to use ripgrep as
922
+ possible. Since the Unlicense is not a proven or well known license, ripgrep
923
+ is also offered under the MIT license, which is ubiquitous and accepted by
924
+ almost everyone.
925
+
926
+ More specifically, ripgrep and all its dependencies are compatible with this
927
+ licensing choice. In particular, ripgrep's dependencies (direct and transitive)
928
+ will always be limited to permissive licenses. That is, ripgrep will never
929
+ depend on code that is not permissively licensed. This means rejecting any
930
+ dependency that uses a copyleft license such as the GPL, LGPL, MPL or any of
931
+ the Creative Commons ShareAlike licenses. Whether the license is "weak"
932
+ copyleft or not does not matter; ripgrep will **not** depend on it.
933
+
934
+
935
+ <h3 name="posix4ever">
936
+ Can ripgrep replace grep?
937
+ </h3>
938
+
939
+ Yes and no.
940
+
941
+ If, upon hearing that "ripgrep can replace grep," you *actually* hear, "ripgrep
942
+ can be used in every instance grep can be used, in exactly the same way, for
943
+ the same use cases, with exactly the same bug-for-bug behavior," then no,
944
+ ripgrep trivially *cannot* replace grep. Moreover, ripgrep will *never* replace
945
+ grep.
946
+
947
+ If, upon hearing that "ripgrep can replace grep," you *actually* hear, "ripgrep
948
+ can replace grep in some cases and not in other use cases," then yes, that is
949
+ indeed true!
950
+
951
+ Let's go over some of those use cases in favor of ripgrep. Some of these may
952
+ not apply to you. That's OK. There may be other use cases not listed here that
953
+ do apply to you. That's OK too.
954
+
955
+ (For all claims related to performance in the following words, see my
956
+ [blog post](https://blog.burntsushi.net/ripgrep/)
957
+ introducing ripgrep.)
958
+
959
+ * Are you frequently searching a repository of code? If so, ripgrep might be a
960
+ good choice since there's likely a good chunk of your repository that you
961
+ don't want to search. grep, can, of course, be made to filter files using
962
+ recursive search, and if you don't mind writing out the requisite `--exclude`
963
+ rules or writing wrapper scripts, then grep might be sufficient. (I'm not
964
+ kidding, I myself did this with grep for almost a decade before writing
965
+ ripgrep.) But if you instead enjoy having a search tool respect your
966
+ `.gitignore`, then ripgrep might be perfect for you!
967
+ * Are you frequently searching non-ASCII text that is UTF-8 encoded? One of
968
+ ripgrep's key features is that it can handle Unicode features in your
969
+ patterns in a way that tends to be faster than GNU grep. Unicode features
970
+ in ripgrep are enabled by default; there is no need to configure your locale
971
+ settings to use ripgrep properly because ripgrep doesn't respect your locale
972
+ settings.
973
+ * Do you need to search UTF-16 files and you don't want to bother explicitly
974
+ transcoding them? Great. ripgrep does this for you automatically. No need
975
+ to enable it.
976
+ * Do you need to search a large directory of large files? ripgrep uses
977
+ parallelism by default, which tends to make it faster than a standard
978
+ `grep -r` search. However, if you're OK writing the occasional
979
+ `find ./ -print0 | xargs -P8 -0 grep` command, then maybe grep is good
980
+ enough.
981
+
982
+ Here are some cases where you might *not* want to use ripgrep. The same caveats
983
+ for the previous section apply.
984
+
985
+ * Are you writing portable shell scripts intended to work in a variety of
986
+ environments? Great, probably not a good idea to use ripgrep! ripgrep has
987
+ nowhere near the ubiquity of grep, so if you do use ripgrep, you might need
988
+ to futz with the installation process more than you would with grep.
989
+ * Do you care about POSIX compatibility? If so, then you can't use ripgrep
990
+ because it never was, isn't and never will be POSIX compatible.
991
+ * Do you hate tools that try to do something smart? If so, ripgrep is all about
992
+ being smart, so you might prefer to just stick with grep.
993
+ * Is there a particular feature of grep you rely on that ripgrep either doesn't
994
+ have or never will have? If the former, file a bug report, maybe ripgrep can
995
+ do it! If the latter, well, then, just use grep.
996
+
997
+
998
+ <h3 name="intentcountsforsomething">
999
+ What does the "rip" in ripgrep mean?
1000
+ </h3>
1001
+
1002
+ When I first started writing ripgrep, I called it `rep`, intending it to be a
1003
+ shorter variant of `grep`. Soon after, I renamed it to `xrep` since `rep`
1004
+ wasn't obvious enough of a name for my taste. And also because adding `x` to
1005
+ anything always makes it better, right?
1006
+
1007
+ Before ripgrep's first public release, I decided that I didn't like `xrep`. I
1008
+ thought it was slightly awkward to type, and despite my previous praise of the
1009
+ letter `x`, I kind of thought it was pretty lame. Being someone who really
1010
+ likes Rust, I wanted to call it "rustgrep" or maybe "rgrep" for short. But I
1011
+ thought that was just as lame, and maybe a little too in-your-face. But I
1012
+ wanted to continue using `r` so I could at least pretend Rust had something to
1013
+ do with it.
1014
+
1015
+ I spent a couple of days trying to think of very short words that began with
1016
+ the letter `r` that were even somewhat related to the task of searching. I
1017
+ don't remember how it popped into my head, but "rip" came up as something that
1018
+ meant "fast," as in, "to rip through your text." The fact that RIP is also
1019
+ an initialism for "Rest in Peace" (as in, "ripgrep kills grep") never really
1020
+ dawned on me. Perhaps the coincidence is too striking to believe that, but
1021
+ I didn't realize it until someone explicitly pointed it out to me after the
1022
+ initial public release. I admit that I found it mildly amusing, but if I had
1023
+ realized it myself before the public release, I probably would have pressed on
1024
+ and chose a different name. Alas, renaming things after a release is hard, so I
1025
+ decided to mush on.
1026
+
1027
+ Given the fact that
1028
+ [ripgrep never was, is or will be a 100% drop-in replacement for
1029
+ grep](#posix4ever),
1030
+ ripgrep is neither actually a "grep killer" nor was it ever intended to be. It
1031
+ certainly does eat into some of its use cases, but that's nothing that other
1032
+ tools like ack or The Silver Searcher weren't already doing.
1033
+
1034
+
1035
+ <h3 name="donations">
1036
+ How can I donate to ripgrep or its maintainers?
1037
+ </h3>
1038
+
1039
+ I welcome [sponsorship](https://github.com/sponsors/BurntSushi/).
1040
+
1041
+ Or if you'd prefer, donating to a charitably organization that you like would
1042
+ also be most welcome. My favorites are:
1043
+
1044
+ * [The Internet Archive](https://archive.org/donate/)
1045
+ * [Rails Girls](https://railsgirlssummerofcode.org/)
1046
+ * [Wikipedia](https://wikimediafoundation.org/support/)