Edit File
edit_fileReplace an exact string in a text file with minimal risk by matching exact text; use dry run to preview changes before applying.
Instructions
Replace an exact string in a text file. Much safer than rewriting the whole file with write_file — the rest of the file is untouched. The old_string must match exactly (including whitespace) and, unless replace_all is true, must appear exactly once; include surrounding lines to make it unique. If you cannot reproduce the text exactly, use edit_lines instead.
Args:
path (string): File to edit.
old_string (string): Exact text to find.
new_string (string): Replacement text.
replace_all (boolean): Replace every occurrence (default false).
dry_run (boolean): Preview the change without writing (default false).
Returns a confirmation plus the edited region with line numbers, so you can verify without re-reading the file.
Example: { "path": "~/app/config.py", "old_string": "DEBUG = True", "new_string": "DEBUG = False" }
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | File to edit | |
| old_string | Yes | Exact text to replace | |
| new_string | Yes | Replacement text | |
| replace_all | No | Replace all occurrences | |
| dry_run | No | Preview without writing |