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
| Name | Required | Description | Default |
|---|---|---|---|
| ignoreCase | No | Whether to ignore case in search (default: false) | |
| pattern | Yes | Search pattern (supports regex) | |
| wholeWord | No | Whether 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.searchInBufferserver.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' }] }; } } );
- src/neovim.ts:643-680 (handler)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'); } }
- src/index.ts:383-386 (schema)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)") },