Open-Source Wikis

/

ripgrep

/

Reference

/

Configuration

BurntSushi/ripgrep

Configuration

ripgrep's runtime configuration comes from three sources, in priority order (later wins):

  1. Defaults baked into each Flag impl in crates/core/flags/defs.rs.
  2. Environment variables read at startup.
  3. The config file pointed at by RIPGREP_CONFIG_PATH.
  4. Command-line arguments passed to rg.

Cumulative flags (e.g., -g/--glob, -t/--type) accumulate across all sources. Non-cumulative flags (e.g., --max-count) take the last value seen.

RIPGREP_CONFIG_PATH

If this environment variable is set and non-empty, ripgrep reads the file at that path during startup. The file is a list of CLI flags, one per line. Empty lines and lines beginning with # are ignored.

Example ~/.config/ripgrep/ripgreprc:

# Always use smart-case
--smart-case

# Include hidden files
--hidden

# Don't print messages about files that can't be read
--no-messages

# Custom file types
--type-add=web:*.{html,css,js}
--type-add=docs:*.{md,rst,txt}

# Custom colors
--colors=path:fg:cyan
--colors=line:fg:yellow
--colors=match:fg:red
--colors=match:style:bold

Implementation: crates/core/flags/config.rs. The parser:

  1. Reads the file and splits it into lines.
  2. Strips comments and blank lines.
  3. Splits each remaining line into argv tokens (one shell-style token per line is the convention).
  4. Prepends those tokens to the command-line argv before parsing.

Argv-given values override config-file values for non-cumulative flags. --no-config skips the config file entirely. RIPGREP_CONFIG_PATH= (empty) also skips.

Environment variables read

Variable Used for File
RIPGREP_CONFIG_PATH Path to the config file crates/core/flags/config.rs
LS_COLORS If --colors is not set, ripgrep uses this for path coloring (when supported) crates/printer/src/color.rs
NO_COLOR If set, disables coloring (per no-color.org) crates/printer/src/color.rs
PCRE2_SYS_STATIC Build-time only; forces static linking of PCRE2 pcre2-sys build script (external)
PATH Used to look up decompression / --pre helpers crates/cli/src/process.rs
HOMEPATH, USERPROFILE (Windows) Used to find the global gitignore crates/ignore/src/gitignore.rs
XDG_CONFIG_HOME, HOME (Unix) Used to find the global gitignore crates/ignore/src/gitignore.rs

Defaults of interest

Default Value Where
Threads min(num_cpus, 12) crates/core/flags/hiargs.rs::threads
Buffer capacity 8 KiB crates/searcher/src/line_buffer.rs::DEFAULT_BUFFER_CAPACITY
mmap threshold Auto: mmap when a single explicit file is given crates/searcher/src/searcher/mmap.rs
Binary detection BinaryDetection::quit(0) for files crates/core/flags/hiargs.rs
Line terminator \n (or \0 with --null-data, or \r\n on Windows-style files when configured) crates/searcher/src/searcher/mod.rs
Default file types ~270 entries crates/ignore/src/default_types.rs
Hyperlink format default (file:// scheme) crates/printer/src/hyperlink/mod.rs

Color customisation

--colors accepts strings of the form KIND:ATTR:VALUE:

  • Kinds: path, line, column, match, highlight (added in 15.0.0).
  • Attributes: fg, bg, style.
  • Values for fg/bg: red, green, blue, yellow, magenta, cyan, white, black, or 256-color / RGB codes.
  • Values for style: bold, nobold, italic (added in 15.0.0), noitalic, underline, nounderline, intense, nointense.

Example: --colors='match:fg:red' --colors='match:style:bold'.

Implementation: crates/printer/src/color.rs::UserColorSpec parses this format; ColorSpecs is the resolved struct.

Special exit codes

Code Meaning
0 At least one match was found, or --quiet was set and exited early
1 No matches found
2 An error occurred (regex parse, I/O, config)

ripgrep treats SIGPIPE (broken pipe) gracefully: when the downstream pipe closes (e.g., rg ... | head), ripgrep returns 0, not a non-zero error code. The handling is in crates/core/main.rs::main.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Configuration – ripgrep wiki | Factory