Skip to main content
Glama

vim_search_replace

Use this tool to find and replace text in Vim, supporting regex, case-insensitive searches, and optional confirmation for each replacement. Access global and precise editing workflows.

Instructions

Find and replace with global, case-insensitive, and confirm options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
confirmNoWhether to confirm each replacement (default: false)
globalNoReplace all occurrences in each line (default: false)
ignoreCaseNoWhether to ignore case in search (default: false)
patternYesSearch pattern (supports regex)
replacementYesReplacement text

Implementation Reference

  • src/index.ts:407-435 (registration)
    Registers the vim_search_replace MCP tool with name, description, Zod input schema, and async handler that delegates to NeovimManager.searchAndReplace.
    server.tool(
      "vim_search_replace",
      "Find and replace with global, case-insensitive, and confirm options",
      {
        pattern: z.string().describe("Search pattern (supports regex)"),
        replacement: z.string().describe("Replacement text"),
        global: z.boolean().optional().describe("Replace all occurrences in each line (default: false)"),
        ignoreCase: z.boolean().optional().describe("Whether to ignore case in search (default: false)"),
        confirm: z.boolean().optional().describe("Whether to confirm each replacement (default: false)")
      },
      async ({ pattern, replacement, global = false, ignoreCase = false, confirm = false }) => {
        try {
          const result = await neovimManager.searchAndReplace(pattern, replacement, { global, ignoreCase, confirm });
          return {
            content: [{
              type: "text",
              text: result
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: error instanceof Error ? error.message : 'Error in search and replace'
            }]
          };
        }
      }
    );
  • Zod schema defining input parameters for the vim_search_replace tool.
    {
      pattern: z.string().describe("Search pattern (supports regex)"),
      replacement: z.string().describe("Replacement text"),
      global: z.boolean().optional().describe("Replace all occurrences in each line (default: false)"),
      ignoreCase: z.boolean().optional().describe("Whether to ignore case in search (default: false)"),
      confirm: z.boolean().optional().describe("Whether to confirm each replacement (default: false)")
    },
  • Implements the core search-and-replace functionality in NeovimManager by constructing and executing a substitute command with configurable flags (g, i, c).
    public async searchAndReplace(pattern: string, replacement: string, options: { global?: boolean; ignoreCase?: boolean; confirm?: boolean } = {}): Promise<string> {
      if (!pattern || pattern.trim().length === 0) {
        throw new NeovimValidationError('Search pattern cannot be empty');
      }
      
      try {
        const nvim = await this.connect();
        
        // Build substitute command
        let flags = '';
        if (options.global) flags += 'g';
        if (options.ignoreCase) flags += 'i';
        if (options.confirm) flags += 'c';
        
        const command = `%s/${pattern.replace(/\//g, '\\/')}/${replacement.replace(/\//g, '\\/')}/${flags}`;
        
        const result = await nvim.call('execute', [command]);
        return result ? String(result).trim() : 'Search and replace completed';
      } catch (error) {
        console.error('Error in search and replace:', error);
        throw new NeovimCommandError(`substitute ${pattern} -> ${replacement}`, error instanceof Error ? error.message : 'Unknown error');
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. While it mentions the three boolean options (global, case-insensitive, confirm), it doesn't disclose important behavioral aspects like whether this operates on the current buffer or all open files, whether changes are saved automatically, what happens if no matches are found, or what the response format looks like. For a mutation tool with zero annotation coverage, this is insufficient.

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 extremely concise - a single sentence that efficiently communicates the core functionality and key options. Every word earns its place with zero wasted text, making it front-loaded and easy to parse.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns, how errors are handled, whether the operation is reversible, or what permissions might be required. Given the complexity of a find-and-replace operation in a text editor context, more behavioral context is needed.

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 already documents all 5 parameters thoroughly. The description mentions the three boolean options (global, case-insensitive, confirm) but adds no additional semantic meaning beyond what's already in the schema descriptions. This meets the baseline of 3 when schema coverage is high.

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 tool's purpose as 'Find and replace' with specific options (global, case-insensitive, confirm), which is a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'vim_search' or 'vim_grep', which might have overlapping search functionality.

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. With multiple sibling tools related to search (vim_search, vim_grep) and editing (vim_edit, vim_command), there's no indication of when this specific find-and-replace operation is appropriate versus other search or editing 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