Skip to content

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.

Terminal window
renamify replace <PATTERN> <REPLACEMENT> [PATHS]... [OPTIONS]
  • <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)
  • --no-regex - Treat pattern as literal string instead of regex
  • --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)
  • --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
  • --exclude-matching-lines <REGEX> - Skip matches on lines matching this regex pattern
  • --commit - Create a git commit after applying changes
  • --force-with-conflicts - Force apply even with conflicts
  • -u - Disable .gitignore files
  • -uu - Disable all ignore files, include hidden files
  • -uuu - Disable all ignore files, include hidden files, process binary files
Terminal window
# Update version numbers with regex
renamify replace 'version: "(\d+)\.(\d+)\.(\d+)"' 'version: "$1.$2.4"'
# Update import paths with capture groups
renamify replace 'from "\./(.*)"' 'from "@local/$1"'
# Fix method names
renamify replace 'get([A-Z]\w+)ById' 'find$1ById'
Terminal window
# Fix a typo without escaping special characters
renamify replace --no-regex 'array[index]' 'array.at(index)'
# Update exact strings
renamify replace --no-regex 'Copyright (c) 2024' 'Copyright (c) 2025'
# Replace configuration values
renamify replace --no-regex 'localhost:3000' 'api.example.com'
Terminal window
# Only in JavaScript files
renamify replace 'console\.log' 'logger.debug' --include "**/*.js"
# Exclude test files
renamify replace 'OLD_API' 'NEW_API' --exclude "**/*.test.*"
Terminal window
# Skip commented lines
renamify replace 'TODO' 'DONE' --exclude-matching-lines '^\s*//'
# Only in import statements
renamify replace '"lodash"' '"lodash-es"' --include "**/*.ts" \
--exclude-matching-lines '^(?!import)'
Terminal window
# Acknowledge large changes
renamify replace 'OldComponent' 'NewComponent' --large
# Dry run first to see scope
renamify replace 'deprecated' 'legacy' --dry-run

The replace command uses Rust’s regex crate, which supports:

Terminal window
# Swap parameters
renamify replace 'fn\((\w+), (\w+)\)' 'fn($2, $1)'
# Extract and reformat
renamify replace 'user_(\d+)_profile' 'profile/user/$1'
Terminal window
# Match any whitespace
renamify replace '\s+' ' '
# Match word boundaries
renamify replace '\btest\b' 'spec'
Terminal window
# Optional trailing comma
renamify replace ',?\s*\]' ']'
# One or more digits
renamify replace 'id:\d+' 'id:REDACTED'
Terminal window
# Positive lookahead
renamify replace '(\w+)(?=\()' 'async $1'
# Negative lookbehind
renamify replace '(?<!\\)n' '\\n'

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.

When pattern matches in filenames:

  • Files are renamed after content changes
  • Directories are renamed depth-first
  • Collisions are detected and reported

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.

TaskUse renameUse 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

Similar to rename, the replace command follows this flow:

  1. Scanning: Searches for pattern matches
  2. Preview: Shows planned changes in chosen format
  3. Confirmation: Prompts “Apply these changes? [y/N]:”
  4. Apply: Makes changes atomically
  5. Results: Shows operation ID for undo
  • 0 - Success
  • 1 - Conflicts detected (use --force-with-conflicts to override)
  • 2 - Invalid input or arguments
  • 3 - Internal error or system issue
  • rename - Case-aware identifier renaming
  • plan - Create a replacement plan without applying
  • undo - Revert the last operation