Replace a line range
nvim_edit_linesReplace file lines with new text using 1-based start/end line numbers. Insert before a line by setting start to end+1. Saves the buffer and returns fresh LSP diagnostics.
Instructions
This is the default way to edit files. Use the provided line numbers to directly replace lines start_line..end_line (1-based, inclusive) with new text. To insert before a line, pass start_line = end_line + 1 (for example start 5, end 4 inserts before line 5). Saves the buffer by default without running format-on-save autocmds, so the diff is minimal. Returns fresh LSP diagnostics for the file. Use nvim_format to format after editing once editing and fixes on that are done.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | File path | |
| save | No | Write the buffer, default true | |
| text | Yes | Replacement text; use \n for several lines | |
| end_line | Yes | Last line to replace, inclusive. start_line - 1 means insert | |
| start_line | Yes | First line to replace, 1-based |