find_and_replace_buf
Find exact text in a Neovim buffer and replace it in-memory, with undoable changes. Requires a unique match; returns error if not found or multiple. Use for targeted edits after reading the buffer content.
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.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | ||
| old_string | Yes | ||
| new_string | Yes |