edit
Performs exact string replacements in files with strict validation of occurrence count. Ensures precise file modifications by matching text exactly, including whitespace and indentation. Ideal for editing existing codebase files while maintaining formatting integrity.
Instructions
Performs exact string replacements in files with strict occurrence count validation.
Usage:
When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: spaces + line number + tab. Everything after that tab is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.
ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
Input Schema
Name | Required | Description | Default |
---|---|---|---|
expected_replacements | No | The expected number of replacements to perform. Defaults to 1 if not specified. | |
file_path | Yes | The absolute path to the file to modify (must be absolute, not relative) | |
new_string | Yes | The edited text to replace the old_string | |
old_string | Yes | The text to replace (must match the file contents exactly, including all whitespace and indentation) |