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")
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the editing modes but fails to explain critical behaviors like whether changes are immediate, if they require saving, error handling for invalid line numbers, or side effects on the buffer state. This leaves significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It's front-loaded with the core purpose and includes essential details about modes, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't cover behavioral aspects like permissions, response format, or error conditions, which are crucial for safe and effective use in a Vim editing context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all three parameters. The description adds no additional meaning beyond what the schema provides, such as examples or edge cases, but doesn't need to compensate for gaps. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Edit buffer content') and specifies the available modes ('insert, replace, or replaceAll'), which distinguishes it from tools like vim_buffer_save or vim_command. However, it doesn't explicitly differentiate from vim_search_replace or other editing-related siblings, keeping it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like vim_search_replace or vim_buffer. It lacks context about prerequisites, such as needing an open buffer, and doesn't mention exclusions or complementary tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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