Skip to main content
Glama

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
NameRequiredDescriptionDefault
linesYesThe text content to insert or use as replacement
modeYesWhether to insert new content, replace existing content, or replace entire buffer
startLineYesThe 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.editLines
    server.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' }] }; } } );
  • 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'; } }
  • 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") },

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bigcodegen/mcp-neovim-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server