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)")
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'regex support and options', hinting at functionality, but fails to describe key behaviors: whether it moves the cursor to matches, highlights results, returns match positions, or has side effects like modifying the buffer. For a search tool with zero annotation coverage, this leaves significant gaps in understanding how it operates.

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 a single, efficient sentence that front-loads the core action ('Search within current buffer') and adds key features ('with regex support and options') without waste. Every word earns its place, making it easy to parse quickly.

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?

Given the complexity of a search operation with regex and options, no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., match count, positions), how errors are handled, or behavioral nuances like search direction. This leaves the agent with insufficient context to use the tool effectively beyond basic invocation.

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 fully documents the three parameters (pattern, ignoreCase, wholeWord) with their types and defaults. The description adds value by confirming regex support for 'pattern' and hinting at 'options', but doesn't provide additional syntax or format details beyond what the schema already states. This meets the baseline for high schema coverage.

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 verb 'Search' and the resource 'within current buffer', making the purpose understandable. It distinguishes from siblings like 'vim_grep' (likely global search) and 'vim_search_replace' (search and replace), though it doesn't explicitly name these alternatives. However, it doesn't fully specify the scope (e.g., search forward/backward, highlight results), keeping it from a perfect score.

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 minimal guidance, mentioning 'regex support and options' but not when to use this tool versus alternatives like 'vim_grep' or 'vim_search_replace'. It lacks explicit context on prerequisites (e.g., requires an open buffer) or exclusions, leaving the agent to infer usage from tool names alone.

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