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'); } }

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