get_current_buffer
Retrieve the currently active Neovim buffer content for real-time editing and Claude integration.
Instructions
Get the currently active buffer in Neovim
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- lib/nvim-operations.js:67-90 (handler)Core handler function that connects to Neovim instances in the current directory, retrieves the current buffer's path and content.export async function getCurrentBuffer() { const instances = await getNvimInstancesInCwd(); if (instances.length === 0) { return null; } // Use the first instance found const { nvim } = instances[0]; try { const currentBuf = await nvim.buffer; const bufName = await currentBuf.name; const lines = await currentBuf.lines; const content = lines.join("\n"); return { path: bufName, content, }; } catch (error) { throw error; } }
- index.js:122-130 (registration)Registers the 'get_current_buffer' tool in the ListToolsRequestSchema handler, including name, description, and empty input schema.{ name: "get_current_buffer", description: "Get the currently active buffer in Neovim", inputSchema: { type: "object", properties: {}, }, }, {
- index.js:210-231 (handler)Dispatches the tool call for 'get_current_buffer' in the CallToolRequestSchema handler, invokes getCurrentBuffer, and formats the MCP response.if (name === "get_current_buffer") { const current = await getCurrentBuffer(); if (!current) { return { content: [ { type: "text", text: "No Neovim instance found in current directory", }, ], }; } return { content: [ { type: "text", text: `Current buffer: ${current.path}\n\n${current.content}`, }, ], }; }
- lib/nvim-operations.js:36-62 (helper)Helper function to find and connect to Neovim instances running in the current working directory, used by getCurrentBuffer.export async function getNvimInstancesInCwd() { const cwd = process.cwd(); const sockets = await findNvimSockets(); const instances = []; for (const socketPath of sockets) { try { const nvim = attach({ socket: socketPath }); const instanceCwd = await nvim.call("getcwd", []); // Check if this nvim instance is in our current directory if (instanceCwd === cwd || instanceCwd.startsWith(cwd + "/")) { instances.push({ socket: socketPath, cwd: instanceCwd, nvim, }); } // Note: We don't quit non-matching instances, just skip them } catch (error) { // Failed to connect to this socket, skip it continue; } } return instances; }