rep is a fast find-and-replace tool, based on fastmod.
Features plain and regex replacement, case-aware rewrites, line-range scoping, interactive preview, line deletion, file listing, stdin mode, and multiple replacements in one pass.
By default rep prints a diff without touching the filesystem; pass --write to apply changes or --preview to step through them interactively.
brew install gechr/tap/repscoop bucket add gechr https://github.com/gechr/scoop-bucket
scoop install gechr/repcargo install --git https://github.com/gechr/rep# Replace "1.2.3" with "4.5.6" in all files
rep 1.2.3 4.5.6
# Replace "foo" with "bar" in "*.txt" files
rep -f txt foo bar
# Replace "foo" with "bar" only on lines 10 through 20 (inclusive)
rep --line-range 10:20 foo bar
# Select a union by repeating the flag or separating ranges with commas
rep -L 10:20 -L 30-40 foo bar
rep -L 10:20,30-40 foo bar
# Replace "foo" with "bar" in all (hidden) files
rep --hidden foo bar
# Replace "foo" with "bar" in all (hidden) Dockerfiles
rep -f '=Dockerfile' --hidden foo bar
# Replace "foo" with "bar" in all files and preview changes
rep --preview foo bar
# Replace "1.2.3" and "3.2.1" with "4.5.6" in all files
rep --regex '[13]\.2\.[13]' 4.5.6
# Swap "foo.bar" with "bar.foo" in all files
rep --regex '(foo)\.(bar)' '$2.$1'
# Replace "foo", "Foo" and "FOO" with "bar"
rep --ignore-case foo bar
# Smart-replace in all files:
# "foo_bar" with "hello_world"
# "FooBar" with "HelloWorld"
# "FOO_BAR" with "HELLO_WORLD"
rep --smart foo_bar hello_world
# Read from stdin and replace "foo" with "bar"
echo foo bar | rep foo bar
rep foo bar < foobar.txt
# Apply multiple replacements in one pass
rep -e foo bar -e baz qux src
# Delete every line containing "TODO"
rep -d TODO
# Print only the total number of replacements without modifying files
rep --dry-run --count foo bar
# Apply replacements and print only the total
rep --write --count foo barRun rep --help for the full reference, including the styling and hyperlink flags.
rep offers two strategies for case-aware replacement. They solve different problems and are mutually exclusive - passing both flags on the command line is an error. A value in ~/.config/rep/config.toml or a REP_* env var can still be overridden by either flag on the command line.
Generates the standard identifier case variants of <find> and <replace> (snake_case, camelCase, PascalCase, kebab-case, SCREAMING_SNAKE_CASE, Train-Case, Ada_Case) and rewrites whichever variant appears in the source to the matching variant of the replacement.
rep --smart foo_bar hello_world| Source | Output |
|---|---|
foo_bar |
hello_world |
fooBar |
helloWorld |
FooBar |
HelloWorld |
FOO_BAR |
HELLO_WORLD |
foo-bar |
hello-world |
Use --smart when renaming an identifier across a codebase that uses several naming conventions for the same logical concept.
Matches the pattern case-insensitively as a literal string, then projects the source's letter-case shape onto the replacement: lowercase, Titlecase, UPPERCASE. Anything else (mixed case) falls back to the replacement as authored.
rep --preserve colour color| Source | Output | Shape |
|---|---|---|
colour |
color |
lowercase |
Colour |
Color |
Titlecase |
COLOUR |
COLOR |
UPPERCASE |
cOlOuR |
color |
mixed → as-authored |
Use --preserve for prose, docs, or string-literal rewrites where the same word appears in different case shapes and you want the replacement to follow each one.
rep reads defaults from ~/.config/rep/config.toml (or $XDG_CONFIG_HOME/rep/config.toml). The file uses TOML; keys mirror the CLI flag names in kebab-case.
# ~/.config/rep/config.toml
hidden = true
ignore-case = true
preview-tool = "delta"
hyperlink-format = "vscode"Precedence is config file < environment variable < CLI flag. Each configurable flag has a matching REP_* env var (e.g. REP_HIDDEN, REP_PREVIEW_TOOL), accepting 1/0/true/false/yes/no/on/off for booleans.
Set REP_CONFIG_PATH to use a different file (e.g. for project-local config), or set it to an empty string to disable config loading entirely.
REP_CONFIG_PATH=./rep.toml rep foo barWrites use a temporary file in the destination directory followed by atomic replacement. Failures before replacement leave the original contents intact. The destination directory must allow creating and replacing files. Permissions and Unix ownership are preserved, or the write fails; platform-specific ACLs and extended attributes are not guaranteed to be preserved.
An explicitly supplied symlink updates its target and keeps the symlink. Replacing a file with multiple hard links updates the named file only; other links keep the original contents. Overlapping search paths and symlink aliases are deduplicated so each destination is processed once.
If a file changes after it is read, rep reports a conflict when it detects the change before committing. Independent files continue processing after an error, and the command exits unsuccessfully if any file could not be processed. Writes are atomic per file, not a transaction across the whole run, and do not guarantee durability after power loss.
File listings and diffs use natural path order. Processing retains a bounded number of files at a time; a finite global hyperlink limit can use temporary disk space to select the final output after counting all replacements. If the output spool cannot be created, rep warns and streams output with hyperlinks disabled. Errors while writing or reading an existing spool still fail the command.
Interactive preview requires valid UTF-8 text and matches at character boundaries. A byte regex that splits a UTF-8 character is rejected in preview; bulk replacement continues to support byte-oriented matching.
Preview saves each individually accepted change before the next prompt. Accepting all remaining changes batches them into one atomic write per file, including any later expressions.