repfor
Safe multi-file string replacement
Search and replace strings across directories with exact matching only - no regex. Dry-run preview, exclude filters, and compact summary output. Built for systematic refactoring.
Features
- Exact string matching only - no regex accidents
- Dry-run mode to preview changes before applying
- Multi-directory and recursive scanning
- File mode for targeting specific files by path
- Multi-line search and replace via \n
- Exclude filtering to prevent unwanted replacements
- Whole-word matching to avoid partial hits
- Atomic writes - temp file + rename prevents data loss
Install
go install github.com/hegner123/repfor@latestThe Problem: Renaming a function across a codebase
# Manual approach: open each file, find/replace, hope you didn't miss one
# Or use sed - risk regex side effects
$ sed -i 's/oldFunc/newFunc/g' ./pkg/**/*.go
# Did "oldFuncHelper" just become "newFuncHelper"?
# Did "myOldFunc" become "myNewFunc"?
# No summary. No dry-run. No safety net.Solution
$ repfor --cli --dir "./pkg/handlers,./pkg/models" --search "oldFunc" --replace "newFunc" --ext .go --whole-word --dry-runOutput
{"directories":[{"dir":"./pkg/handlers","files_modified":2,"lines_changed":5,"total_replacements":8,"files":[{"path":"user.go","lines_changed":3,"replacements":5},{"path":"auth.go","lines_changed":2,"replacements":3}]},{"dir":"./pkg/models","files_modified":1,"lines_changed":2,"total_replacements":3,"files":[{"path":"user.go","lines_changed":2,"replacements":3}]}],"dry_run":true}Comparison
| Metric | Value |
|---|---|
| Safety | No regex - exact string matching only |
| Atomic writes | Zero data loss on write failures |
| Workflow | checkfor -> dry_run -> apply -> verify |