Rename vs. Replace
Renamify provides two distinct commands for different use cases: rename for intelligent case-aware renaming across naming conventions, and replace for straightforward regex or literal string replacements.
When to Use Replace
Section titled “When to Use Replace”The replace command brings simple, powerful search-and-replace to the CLI and
AI agents:
# Regex replacement with capture groupsrenamify replace 'foo-(.+)' 'bar-$1'
# Literal string replacement (no regex)renamify replace --no-regex 'exact[string]' 'new[string]'-
AI Agent Efficiency: AI coding assistants often waste time updating files one-by-one or struggling with
sedsyntax differences across platforms. Thereplacecommand gives them a reliable, cross-platform tool that works the first time. -
Both Contents and Paths: Most editors already have excellent regex search-and-replace, but very few also allow you to rename files and directories at the same time. The
replacecommand replaces the search string in both contents and filenames. -
CLI Power Users: Instead of running multiple
sedandfindcommands (and hoping they work across macOS/Linux/BSD), you get one consistent CLI interface that works across all platforms.
Replace Features
Section titled “Replace Features”- Regex by default with full capture group support (
$1,$2, etc.) - Literal mode (
--no-regex) for when you don’t want to escape special characters - Renames files and directories - Also replaces the search string in filenames, not just file contents
- Same safety features as rename: preview, atomic apply, undo/redo
- Same scope control: respects
.gitignore, supports--include/--excludepatterns - Cross-platform: Works identically on macOS, Linux, and Windows
Replace Examples
Section titled “Replace Examples”# Rename a module and the filename / directoryrenamify replace 'old_module' 'new_module'
# Only replace the contents but don't rename files or directoriesrenamify replace 'old_module' 'new_module' --no-rename-files
# Update version numbersrenamify replace 'version: "1\.2\.3"' 'version: "1.3.0"'
# Fix import pathsrenamify replace 'from "@old/(.+)"' 'from "@new/$1"'
# Fix a typo in a URL (literal mode)renamify replace --no-regex 'https://exmaple.com' 'https://example.com'When to Use Rename
Section titled “When to Use Rename”The rename command is for intelligent identifier renaming that preserves code
style conventions. Use it when you need to rename variables, functions, classes,
or modules across different naming styles.
TLDR: Renamify’s rename tokenizes identifiers, understands case styles and separators, knows common acronyms, respects boundaries, renames files and directories consistently, previews the plan, and applies changes atomically with undo.
1. Case style preservation across variants
Section titled “1. Case style preservation across variants”Example: rename acronym to inflection_rule.
Your codebase contains:
acronym_set # snake_caseacronymSet # camelCaseAcronymSet # PascalCaseACRONYM_SET # SCREAMING_SNAKE_CASEacronym-set # kebab-caseAcronym-Set # Train-Case--exclude-acronyms # CLI flag segmentexcludeAcronyms # mixed-case config keyNaive replace produces broken or mixed results:
inflection_rule_set # okinflection_ruleSet # wrong in camelInflection_ruleSet # broken PascalINFLECTION_RULE_SET # okinflection_rule-set # mixed separatorsInflection_rule-Set # broken Train--exclude-inflection_rules # wrong plural placementexcludeInflection_rules # broken camel suffixRenamify produces consistent, style-aware results:
inflection_rule_setinflectionRuleSetInflectionRuleSetINFLECTION_RULE_SETinflection-rule-setInflection-Rule-Set--exclude-inflection-rulesexcludeInflectionRulesHow: we detect the container style, generate the correct target variant for that style, and only replace full tokens, not substrings.
2. Compound word boundaries
Section titled “2. Compound word boundaries”Example: rename File to Document.
Input:
FileManagerTempFileHandlerfile_manager_serviceProfileImage # should not changeFileSystemWatcherNaive regex can overmatch:
ProfileImage -> ProDocumentImage # wrongRenamify honors token boundaries:
FileManager -> DocumentManagerTempFileHandler -> TempDocumentHandlerfile_manager_service -> document_manager_serviceProfileImage -> ProfileImageFileSystemWatcher -> DocumentSystemWatcher3. Acronym intelligence for matching
Section titled “3. Acronym intelligence for matching”Acronyms are common: HTTPSConnection, XMLHttpRequest, parseURL, ID,
URLParser.
Renamify’s tokenizer understands acronym spans for matching:
HTMLGeneratoris parsed asHTML+Generator, so searches forhtml_generatororHTMLGeneratorboth match correctly.Rename-Tool-CLIis Train-Case with an acronym tail. Searching forrename_toolcorrectly matches theRename-Toolsubspan and preserves-CLI.
Acronym matching is configurable:
--no-acronymsdisables acronym-aware matching.--include-acronyms "API,CLI,ID"--exclude-acronyms "ID"--only-acronyms "API,CLI"
Note: snake_case is always lower for matching and rendering. Screaming snake is the uppercase variant. Acronym options affect matching detection and case inference, not whether snake uses uppercase.
4. File and directory renaming with consistency
Section titled “4. File and directory renaming with consistency”Renamify updates file and directory names alongside contents, in the right order, and checks for collisions.
Example: rename smart_search_and_replace to renamify.
It handles:
/smart_search_and_replace/ -> /renamify//docs/smart-search-and-replace-guide.md -> /docs/renamify-guide.mdsmart_search_and_replace.exe -> renamify.exeSmartSearchAndReplace.java -> Renamify.javaAnd updates common import patterns:
import smart_search_and_replace.core -> import renamify.corerequire('smart-search-and-replace') -> require('renamify')use smart_search_and_replace::scanner; -> use renamify::scanner;Root directory rename is suggested with a ready-to-paste snippet and opt-in flag to perform automatically.
5. Hyphenated mixed-style patterns
Section titled “5. Hyphenated mixed-style patterns”Real-world examples:
SmartSearchAndReplace-specificsmart-search-and-replace-GuideRun-SmartSearchAndReplaceRenamify treats the hyphen as a separator between differently styled segments, replaces only the matching subspan, and preserves each segment’s style. For example:
Rename-Tool-CLI -> Code-Transform-Engine-CLIThis works because the tokenizer classifies the segment as Train-Case with an acronym tail, not as generic “mixed”.
6. Special tokens that must be preserved
Section titled “6. Special tokens that must be preserved”Renamify never splits these incorrectly:
arm64,amd642FAK8Sproject1,b2b,b2c
These are single tokens with digits and are preserved in style-aware replacements.
7. Round-trip preservation
Section titled “7. Round-trip preservation”Renames must be reversible without drift:
project1 -> workspace1 -> project1b2b_sales -> b2c_sales -> b2b_salesARM64_ARCH -> X86_ARCH -> ARM64_ARCHRenamify tracks exact tokenization and case rules so round-trips restore the original. We run end-to-end roundtrip tests on CI to ensure we catch any unhandled edgecases.
Safety Features (Both Commands)
Section titled “Safety Features (Both Commands)”Both rename and replace share the same safety infrastructure:
- Ignores binaries and build artifacts by default. (Same rules as ripgrep, same -u, -uu, -uuu flags.)
- Honors
.gitignore,.ignore,.rgignore, and.rnignore. - Plan and preview before apply.
- Apply is atomic with rollback and undo history.
Quick Comparison
Section titled “Quick Comparison”| Feature | rename | replace |
|---|---|---|
| Case-aware transformations | ✅ | ❌ |
| Regex patterns | ❌ | ✅ |
| Capture groups | ❌ | ✅ |
| Literal string mode | ❌ | ✅ |
| Acronym detection | ✅ | ❌ |
| Token boundary respect | ✅ | ❌ |
| File/directory renaming | ✅ | ✅ |
| Preview & undo | ✅ | ✅ |
| Atomic apply | ✅ | ✅ |
Real-world Examples
Section titled “Real-world Examples”Using Rename: Refactoring URL to WebAddress
Section titled “Using Rename: Refactoring URL to WebAddress”Challenges include:
URLParser,parseURL,HTTPS_URL,url_encoder- Plurals like
URLsvsWebAddresses - Words that only contain
URLbut are different, likeCURL - Literals and comments, like
https://example.com/urlor@param {URL} - Constants like
URL_PATTERN - Filenames like
url_utils.jsthat should becomeweb_address_utils.js
renamify rename URL WebAddressUsing Replace: Update API Endpoints
Section titled “Using Replace: Update API Endpoints”When you need to update API paths without case transformation:
# Update API version in all endpointsrenamify replace '/api/v1/(.+)' '/api/v2/$1'
# Fix a consistent typorenamify replace --no-regex 'recieve' 'receive'