renamify replace
The replace
command performs straightforward search-and-replace operations
using regular expressions or literal strings. Unlike the rename
command which
handles case transformations, replace
is for mechanical replacements where you
control the exact pattern and replacement.
renamify replace <PATTERN> <REPLACEMENT> [PATHS]... [OPTIONS]
Arguments
Section titled “Arguments”<PATTERN>
- Search pattern (regex by default, literal with —no-regex)<REPLACEMENT>
- Replacement string (supports $1, $2 capture groups in regex mode)[PATHS]...
- Search paths (files or directories)
Options
Section titled “Options”Pattern Mode
Section titled “Pattern Mode”--no-regex
- Treat pattern as literal string instead of regex
Preview and Confirmation
Section titled “Preview and Confirmation”--preview <FORMAT>
- Show preview before confirmation (table, diff, json, none) [default: table]--dry-run
- Show preview only, don’t apply changes--yes
/-y
- Skip confirmation prompt and apply immediately--large
- Acknowledge large changes (>500 files or >100 renames)
File Processing
Section titled “File Processing”--include <PATTERNS>
- Only process files matching these glob patterns--exclude <PATTERNS>
- Skip files matching these glob patterns--no-rename-files
- Don’t rename matching files--no-rename-dirs
- Don’t rename matching directories--no-rename-paths
- Don’t rename files or directories
Line Filtering
Section titled “Line Filtering”--exclude-matching-lines <REGEX>
- Skip matches on lines matching this regex pattern
Safety and Git
Section titled “Safety and Git”--commit
- Create a git commit after applying changes--force-with-conflicts
- Force apply even with conflicts
Unrestricted Mode
Section titled “Unrestricted Mode”-u
- Disable .gitignore files-uu
- Disable all ignore files, include hidden files-uuu
- Disable all ignore files, include hidden files, process binary files
Examples
Section titled “Examples”Basic Regex Replacement
Section titled “Basic Regex Replacement”# Update version numbers with regexrenamify replace 'version: "(\d+)\.(\d+)\.(\d+)"' 'version: "$1.$2.4"'
# Update import paths with capture groupsrenamify replace 'from "\./(.*)"' 'from "@local/$1"'
# Fix method namesrenamify replace 'get([A-Z]\w+)ById' 'find$1ById'
Literal String Mode
Section titled “Literal String Mode”# Fix a typo without escaping special charactersrenamify replace --no-regex 'array[index]' 'array.at(index)'
# Update exact stringsrenamify replace --no-regex 'Copyright (c) 2024' 'Copyright (c) 2025'
# Replace configuration valuesrenamify replace --no-regex 'localhost:3000' 'api.example.com'
File Type Specific
Section titled “File Type Specific”# Only in JavaScript filesrenamify replace 'console\.log' 'logger.debug' --include "**/*.js"
# Exclude test filesrenamify replace 'OLD_API' 'NEW_API' --exclude "**/*.test.*"
With Line Filtering
Section titled “With Line Filtering”# Skip commented linesrenamify replace 'TODO' 'DONE' --exclude-matching-lines '^\s*//'
# Only in import statementsrenamify replace '"lodash"' '"lodash-es"' --include "**/*.ts" \ --exclude-matching-lines '^(?!import)'
Large Codebase
Section titled “Large Codebase”# Acknowledge large changesrenamify replace 'OldComponent' 'NewComponent' --large
# Dry run first to see scoperenamify replace 'deprecated' 'legacy' --dry-run
Regex Features
Section titled “Regex Features”The replace command uses Rust’s regex crate, which supports:
Capture Groups
Section titled “Capture Groups”# Swap parametersrenamify replace 'fn\((\w+), (\w+)\)' 'fn($2, $1)'
# Extract and reformatrenamify replace 'user_(\d+)_profile' 'profile/user/$1'
Character Classes
Section titled “Character Classes”# Match any whitespacerenamify replace '\s+' ' '
# Match word boundariesrenamify replace '\btest\b' 'spec'
Quantifiers
Section titled “Quantifiers”# Optional trailing commarenamify replace ',?\s*\]' ']'
# One or more digitsrenamify replace 'id:\d+' 'id:REDACTED'
Lookarounds
Section titled “Lookarounds”# Positive lookaheadrenamify replace '(\w+)(?=\()' 'async $1'
# Negative lookbehindrenamify replace '(?<!\\)n' '\\n'
Important Notes
Section titled “Important Notes”No Case Transformation
Section titled “No Case Transformation”Unlike rename
, the replace
command does NOT:
- Transform between case styles (snake_case, camelCase, etc.)
- Respect token boundaries
- Handle acronyms specially
- Generate style variants
If you need these features, use the rename
command instead.
File Renaming
Section titled “File Renaming”When pattern matches in filenames:
- Files are renamed after content changes
- Directories are renamed depth-first
- Collisions are detected and reported
Escaping in Regex Mode
Section titled “Escaping in Regex Mode”Common patterns that need escaping:
- Dots:
\.
for literal dot - Parentheses:
\(
and\)
for literal - Square brackets:
\[
and\]
- Special chars:
\$
,\^
,\*
,\+
,\?
Use --no-regex
to avoid escaping entirely.
Comparison with rename
Section titled “Comparison with rename”Task | Use rename | Use replace |
---|---|---|
Rename a variable across case styles | ✅ | ❌ |
Update version numbers | ❌ | ✅ |
Fix typos | ❌ | ✅ |
Refactor class names | ✅ | ❌ |
Update config values | ❌ | ✅ |
Change import paths | ❌ | ✅ |
Rename functions preserving style | ✅ | ❌ |
Interactive Flow
Section titled “Interactive Flow”Similar to rename
, the replace command follows this flow:
- Scanning: Searches for pattern matches
- Preview: Shows planned changes in chosen format
- Confirmation: Prompts “Apply these changes? [y/N]:”
- Apply: Makes changes atomically
- Results: Shows operation ID for undo
Exit Codes
Section titled “Exit Codes”0
- Success1
- Conflicts detected (use--force-with-conflicts
to override)2
- Invalid input or arguments3
- Internal error or system issue