Skip to main content
Glama

vim_search

Search within the current Vim buffer using regex, with options to ignore case or match whole words, enhancing text editing efficiency.

Instructions

Search within current buffer with regex support and options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ignoreCaseNoWhether to ignore case in search (default: false)
patternYesSearch pattern (supports regex)
wholeWordNoWhether to match whole words only (default: false)

Implementation Reference

  • src/index.ts:379-405 (registration)
    Registers the 'vim_search' tool, defines input schema using Zod, and provides thin handler that delegates to NeovimManager.searchInBuffer
    server.tool( "vim_search", "Search within current buffer with regex support and options", { pattern: z.string().describe("Search pattern (supports regex)"), ignoreCase: z.boolean().optional().describe("Whether to ignore case in search (default: false)"), wholeWord: z.boolean().optional().describe("Whether to match whole words only (default: false)") }, async ({ pattern, ignoreCase = false, wholeWord = false }) => { try { const result = await neovimManager.searchInBuffer(pattern, { ignoreCase, wholeWord }); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : 'Error searching in buffer' }] }; } } );
  • Core handler implementation in NeovimManager that performs regex search in the current buffer using Neovim APIs like searchcount and sets search options (ignorecase, wholeword).
    public async searchInBuffer(pattern: string, options: { ignoreCase?: boolean; wholeWord?: boolean } = {}): Promise<string> { if (!pattern || pattern.trim().length === 0) { throw new NeovimValidationError('Search pattern cannot be empty'); } try { const nvim = await this.connect(); // Build search command with options let searchPattern = pattern; if (options.wholeWord) { searchPattern = `\\<${pattern}\\>`; } // Set search options if (options.ignoreCase) { await nvim.command('set ignorecase'); } else { await nvim.command('set noignorecase'); } // Perform search and get matches const matches = await nvim.eval(`searchcount({"pattern": "${searchPattern.replace(/"/g, '\\"')}", "maxcount": 100})`); const matchInfo = matches as { current: number; total: number; maxcount: number; incomplete: number }; if (matchInfo.total === 0) { return `No matches found for: ${pattern}`; } // Move to first match await nvim.command(`/${searchPattern}`); return `Found ${matchInfo.total} matches for: ${pattern}${matchInfo.incomplete ? ' (showing first 100)' : ''}`; } catch (error) { console.error('Error searching in buffer:', error); throw new NeovimCommandError(`search for ${pattern}`, error instanceof Error ? error.message : 'Unknown error'); } }
  • Zod schema defining input parameters for vim_search tool: pattern (required string), ignoreCase and wholeWord (optional booleans)
    pattern: z.string().describe("Search pattern (supports regex)"), ignoreCase: z.boolean().optional().describe("Whether to ignore case in search (default: false)"), wholeWord: z.boolean().optional().describe("Whether to match whole words only (default: false)") },

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