vim_buffer_save
Save the current buffer or to a specified filename directly within the MCP Neovim Server, streamlining text editing and file management workflows.
Instructions
Save current buffer or save to specific filename
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "vim_buffer_save"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | No | Optional filename to save buffer to (defaults to current buffer's filename) |
Implementation Reference
- src/neovim.ts:599-626 (handler)Core implementation of buffer saving logic in NeovimManager.saveBuffer method, which executes Neovim :write command
public async saveBuffer(filename?: string): Promise<string> { try { const nvim = await this.connect(); if (filename) { // Save with specific filename await nvim.command(`write ${filename}`); return `Buffer saved to: ${filename}`; } else { // Save current buffer const buffer = await nvim.buffer; const bufferName = await buffer.name; if (!bufferName) { throw new NeovimValidationError('Cannot save unnamed buffer without specifying filename'); } await nvim.command('write'); return `Buffer saved: ${bufferName}`; } } catch (error) { if (error instanceof NeovimValidationError) { throw error; } console.error('Error saving buffer:', error); throw new NeovimCommandError(`save ${filename || 'current buffer'}`, error instanceof Error ? error.message : 'Unknown error'); } } - src/index.ts:332-349 (handler)MCP tool handler function for vim_buffer_save that wraps neovimManager.saveBuffer and formats the response
async ({ filename }) => { try { const result = await neovimManager.saveBuffer(filename); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : 'Error saving buffer' }] }; } } - src/index.ts:330-331 (schema)Zod input schema definition for the vim_buffer_save tool parameters
filename: z.string().optional().describe("Optional filename to save buffer to (defaults to current buffer's filename)") }, - src/index.ts:326-350 (registration)Registration of the vim_buffer_save tool with MCP server including name, description, schema, and handler
server.tool( "vim_buffer_save", "Save current buffer or save to specific filename", { filename: z.string().optional().describe("Optional filename to save buffer to (defaults to current buffer's filename)") }, async ({ filename }) => { try { const result = await neovimManager.saveBuffer(filename); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : 'Error saving buffer' }] }; } } );