update_buffer
Modify Neovim buffer content directly from Claude to reflect changes instantly in the editor.
Instructions
Update the content of a buffer in Neovim. Changes appear immediately in the editor.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | The file path of the buffer to update | |
| content | Yes | The new content for the buffer |
Implementation Reference
- lib/nvim-operations.js:154-176 (handler)The handler function that updates the content of a Neovim buffer by path using the neovim API.export async function updateBuffer(bufferPath, newContent) { const instances = await getNvimInstancesInCwd(); for (const { nvim } of instances) { try { const buffers = await nvim.buffers; for (const buf of buffers) { const name = await buf.name; if (name === bufferPath) { const lines = newContent.split("\n"); await buf.setLines(lines, { start: 0, end: -1 }); return { success: true, path: bufferPath }; } } } catch (error) { console.error("Error updating buffer:", error.message); } } throw new Error(`Buffer not found: ${bufferPath}`); }
- index.js:144-162 (schema)Tool schema definition including input schema for path and content parameters.{ name: "update_buffer", description: "Update the content of a buffer in Neovim. Changes appear immediately in the editor.", inputSchema: { type: "object", properties: { path: { type: "string", description: "The file path of the buffer to update", }, content: { type: "string", description: "The new content for the buffer", }, }, required: ["path", "content"], }, },
- index.js:245-255 (registration)Registration and dispatch logic in the CallToolRequest handler that invokes the updateBuffer function.if (name === "update_buffer") { const result = await updateBuffer(args.path, args.content); return { content: [ { type: "text", text: `Successfully updated buffer: ${result.path}`, }, ], }; }