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
Input Schema
TableJSON 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 commandpublic 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 responseasync ({ 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 parametersfilename: 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 handlerserver.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' }] }; } } );