Skip to main content
Glama

vim_grep

Perform project-wide searches using vimgrep and populate the quickfix list for efficient navigation. Specify search patterns and file patterns to locate content in codebases quickly.

Instructions

Project-wide search using vimgrep with quickfix list

Input Schema

NameRequiredDescriptionDefault
filePatternNoFile pattern to search in (default: **/* for all files)
patternYesSearch pattern to grep for

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "filePattern": { "description": "File pattern to search in (default: **/* for all files)", "type": "string" }, "pattern": { "description": "Search pattern to grep for", "type": "string" } }, "required": [ "pattern" ], "type": "object" }

Implementation Reference

  • Core handler function that executes vimgrep in Neovim, retrieves quickfix list, and formats search results for the vim_grep tool.
    public async grepInProject(pattern: string, filePattern: string = '**/*'): Promise<string> { if (!pattern || pattern.trim().length === 0) { throw new NeovimValidationError('Grep pattern cannot be empty'); } try { const nvim = await this.connect(); // Use vimgrep for internal searching const command = `vimgrep /${pattern}/ ${filePattern}`; await nvim.command(command); // Get quickfix list const qflist = await nvim.eval('getqflist()'); const results = qflist as Array<{ filename: string; lnum: number; text: string }>; if (results.length === 0) { return `No matches found for: ${pattern}`; } const summary = results.slice(0, 10).map(item => `${item.filename}:${item.lnum}: ${item.text.trim()}` ).join('\n'); const totalText = results.length > 10 ? `\n... and ${results.length - 10} more matches` : ''; return `Found ${results.length} matches for: ${pattern}\n${summary}${totalText}`; } catch (error) { console.error('Error in grep:', error); throw new NeovimCommandError(`grep ${pattern}`, error instanceof Error ? error.message : 'Unknown error'); } }
  • src/index.ts:437-462 (registration)
    Registers the vim_grep tool using server.tool(), including description, input schema, and thin async handler that delegates to neovimManager.grepInProject and formats MCP response.
    server.tool( "vim_grep", "Project-wide search using vimgrep with quickfix list", { pattern: z.string().describe("Search pattern to grep for"), filePattern: z.string().optional().describe("File pattern to search in (default: **/* for all files)") }, async ({ pattern, filePattern = "**/*" }) => { try { const result = await neovimManager.grepInProject(pattern, filePattern); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : 'Error in grep search' }] }; } } );
  • Zod input schema definition for the vim_grep tool parameters.
    { pattern: z.string().describe("Search pattern to grep for"), filePattern: z.string().optional().describe("File pattern to search in (default: **/* for all files)")

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