ripgrep Cheat Sheet

A cheat sheet in English by njones
12,469 views 4,520 downloads 21 Feb 2020 History
4.9 avg · 1 rating

File and Path Selection

--binary
Enable binary file searching
-L
Follow symbolic links (not default)
-g <GL­OB>
Include or exclude files and direct­ories. Overrides any other ignore logic.
--iglob <GL­OB>
Like -g but case-i­nse­nsitive
--no-i­gnore
Don't respect any ignore files
-z
Search in compressed files
-t <T>
-T <T>
Only search for (-t) / exclude (-T) files of TYPE. Use --type­-list to show all
Globbing rules match .gitignore style. Precede glob with a ! to exclude.

There are several other options to not respect only certain ignore files: ‑‑no‑ignore‑dot, ‑‑no‑ignore‑global, ‑‑no‑ignore‑parent, and ‑‑no‑ignore‑vcs.

The -z option requires decompression binaries to be on the PATH. Consider instead the ripgrep-all variant.

Matcher Selection

-F
Treat pattern as literal string
-P
Use the PCRE2 regex engine
--auto­-hy­bri­d-regex
Choose regex engine based on features used in pattern
Use the PCRE2 engine to support look-a­round or backre­fer­ences.

Matching Control

-s
Search case-s­ens­itively
-S
Search case-i­nse­nsi­tively if pattern is all lowercase, otherwise sensit­ively
--crlf
Treat CRLF as line terminator for $
--pre <CM­D>
Preprocess file with CMD before searching
--pre-glob
  <GL­OB>
Used to specify which files to preprocess
-e
Used to specify multiple patterns or protect patterns starting with "­-"
-w,
--word-regexp
Only matches surrounded by word boundaries
-c
Count matched lines/file
--coun­t-m­atches
Count matches per file

Other Options

--no-m­essages
Hide file open/read errs
--bloc­k-b­uffered
Flush on in-memory buffer size (default in pipeline or to file)
--line­-bu­ffered
Flush per line (default in terminal)
--encoding <EN­C>
Encoding for reading files (e.g. utf-8, utf-16, ascii, window­s-1252)
-j <NU­M>
Approx threads to use
-[A|B|C] <nu­m>
Show <nu­m> lines after each match (A), before (B), or before and after (C)
More encodings here.

Output Options

--color <WH­EN>
auto, never, always, or ansi (emit ANSI escapes).
--column
Show column numbers (1-based) for first match
-l
Show only names of matching files
--files-without-
match
Show only names of non-matching files
--no-h­eading
File path at start of line instead of before group
-I
Never print file name
-N
Suppress line numbers
-0, --null
Follow any file path with a NUL byte
--null­-data
Use NUL as a line terminator instead of '­\n'
-o
Print only match
--path-separator
  <S>
Alt char for outputting path separator
-p, --pretty
Alias for ‑‑color always ‑‑heading ‑‑line­‑number
-r <TE­XT>
Replace match with <TE­XT> in output (will never modify files)
--sort <SO­RTB­Y>
Sorts results ascending (--sortr for descen­ding). Options: path, modified, accessed, created, none
--trim
Trim lead whitespace
-q
Quiet, no output

Badges

Nice Cheat Sheet

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.