Edit Lines
edit_linesEdit files by line number to replace, insert, or delete lines. Use when you know the location but not the exact text.
Instructions
Edit a file by line numbers: replace a line range, insert text, or delete lines. Use read_file with line_numbers=true first to get the exact numbers. Prefer edit_file when you can copy the exact text; use this when you know the location but not the exact characters. IMPORTANT: line numbers shift after every edit — re-read the file before making another line-based edit.
Args:
path (string): File to edit.
mode ('replace'|'insert_before'|'insert_after'|'delete'): What to do (default 'replace').
start_line (number): First line affected (1-based, inclusive).
end_line (number): Last line affected (default start_line). Ignored for inserts.
new_text (string): The new lines (required except for delete).
dry_run (boolean): Preview the change without writing (default false).
Returns a confirmation plus the edited region with line numbers.
Example: { "path": "~/app.py", "mode": "replace", "start_line": 12, "end_line": 14, "new_text": "def main():\n run()" }
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | File to edit | |
| mode | No | Edit operation | replace |
| start_line | Yes | First line (1-based) | |
| end_line | No | Last line (default start_line) | |
| new_text | No | Replacement/inserted text (not used for delete) | |
| dry_run | No | Preview without writing |