vim_edit
Modify buffer content in a Vim environment using insert, replace, or replaceAll modes. Specify start line, mode, and text to edit efficiently within the mcp-neovim-server.
Instructions
Edit buffer content using insert, replace, or replaceAll modes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lines | Yes | The text content to insert or use as replacement | |
| mode | Yes | Whether to insert new content, replace existing content, or replace entire buffer | |
| startLine | Yes | The line number where editing should begin (1-indexed) |
Implementation Reference
- src/index.ts:160-186 (registration)Registers the vim_edit MCP tool including schema validation and thin wrapper handler that delegates to NeovimManager.editLinesserver.tool( "vim_edit", "Edit buffer content using insert, replace, or replaceAll modes", { startLine: z.number().describe("The line number where editing should begin (1-indexed)"), mode: z.enum(["insert", "replace", "replaceAll"]).describe("Whether to insert new content, replace existing content, or replace entire buffer"), lines: z.string().describe("The text content to insert or use as replacement") }, async ({ startLine, mode, lines }) => { try { const result = await neovimManager.editLines(startLine, mode, lines); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : 'Error editing buffer' }] }; } } );
- src/neovim.ts:440-466 (handler)The core handler logic that connects to Neovim and performs buffer modifications using insert, replace, or replaceAll modes via the Neovim buffer API.public async editLines(startLine: number, mode: 'replace' | 'insert' | 'replaceAll', newText: string): Promise<string> { try { const nvim = await this.connect(); const splitByLines = newText.split('\n'); const buffer = await nvim.buffer; if (mode === 'replaceAll') { // Handle full buffer replacement const lineCount = await buffer.length; // Delete all lines and then append new content await buffer.remove(0, lineCount, true); await buffer.insert(splitByLines, 0); return 'Buffer completely replaced'; } else if (mode === 'replace') { await buffer.replace(splitByLines, startLine - 1); return 'Lines replaced successfully'; } else if (mode === 'insert') { await buffer.insert(splitByLines, startLine - 1); return 'Lines inserted successfully'; } return 'Invalid mode specified'; } catch (error) { console.error('Error editing lines:', error); return 'Error editing lines'; } }
- src/index.ts:163-167 (schema)Zod input schema for the vim_edit tool defining parameters: startLine, mode (insert/replace/replaceAll), and lines.{ startLine: z.number().describe("The line number where editing should begin (1-indexed)"), mode: z.enum(["insert", "replace", "replaceAll"]).describe("Whether to insert new content, replace existing content, or replace entire buffer"), lines: z.string().describe("The text content to insert or use as replacement") },