Edit files using find-and-replace. Must read file first with view.
<when_to_use> Use Edit when:
- Making targeted changes to existing code
- Changing specific functions, lines, or blocks
- Single file, 1-3 changes
Do NOT use Edit when:
- Creating new files β use
write - Complete file rewrite β use
write - Multiple changes to same file β use
multiedit - Moving/renaming files β use
bashwithmv</when_to_use>
<critical_rule>
ALWAYS view the file first. The old_string must match EXACTLYβevery space, tab, newline, and blank line.
</critical_rule>
<special_cases>
- Create file: provide file_path + new_string, leave old_string empty
- Delete content: provide file_path + old_string, leave new_string empty </special_cases>
<matching_rules> Include 3-5 lines of context to ensure unique match:
Good: Match entire function signature + first lines
old_string: "func ProcessUser(id string) error {\n if id == \"\" {\n return errors.New(\"empty\")\n }"
Bad: Match just one line that appears many times
old_string: "return nil"
Tip: In large files, include the function or class signature as context to disambiguate similar code blocks. </matching_rules>
<common_failures>
Expected: " func foo() {" (4 spaces)
Provided: " func foo() {" (2 spaces) β
Expected: "}\n\nfunc bar()" (blank line between)
Provided: "}\nfunc bar()" (no blank line) β
Expected: "// comment" (space after //)
Provided: "//comment" β
</common_failures>
If "old_string not found": 1. `view` the file at target location 2. Copy exact text character-by-character 3. Include more surrounding context 4. Check tabs vs spaces, blank lines