find_and_replace_buf
Replace an exact string in a Neovim buffer with new text, requiring a unique match to avoid errors. Edits occur in-memory and remain undoable until the user saves.
Instructions
Find and replace text in a Neovim buffer. The edit happens in-memory and is fully undoable — nothing is written to disk until the user saves.
file: path relative to Neovim's cwd (as shown in get_state buffers).
old_string: the exact text to find. Must match exactly once in the
buffer; returns an error if not found or if it matches multiple
locations. Include surrounding lines to disambiguate.
new_string: the replacement text.
Creates the buffer if it doesn't already exist. Use this for targeted
edits. Use write_full_buf instead when replacing the entire buffer
content. Use read_full_buf or read_buf_range first if you need
to see the current content before editing.
Returns {start_line, lines_removed, lines_added, total_lines} on success, or {error} with a message on failure.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"file": "<file>",
"old_string": "<old_string>",
"new_string": "<new_string>"
},
"name": "find_and_replace_buf"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | ||
| new_string | Yes | ||
| old_string | Yes |