Skip to main content
Glama

vim_fold

Manage code folding in Neovim by creating, opening, closing, toggling, or deleting folds. Specify start and end lines for precise fold creation, enhancing code readability and navigation.

Instructions

Manage code folding: create, open, close, and toggle folds

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesFolding action to perform
endLineNoEnd line for creating fold (required for create)
startLineNoStart line for creating fold (required for create)

Implementation Reference

  • Core handler implementation for vim_fold tool. Executes specific Neovim folding commands (zf, zo, zc, za, zR, zM, zd) based on the action parameter, with validation for manual fold creation.
    public async manageFold(action: string, startLine?: number, endLine?: number): Promise<string> {
      try {
        const nvim = await this.connect();
        
        switch (action) {
          case 'create':
            if (startLine === undefined || endLine === undefined) {
              throw new NeovimValidationError('Start line and end line are required for creating folds');
            }
            await nvim.command(`${startLine},${endLine}fold`);
            return `Created fold from line ${startLine} to ${endLine}`;
            
          case 'open':
            await nvim.input('zo');
            return 'Opened fold at cursor';
            
          case 'close':
            await nvim.input('zc');
            return 'Closed fold at cursor';
            
          case 'toggle':
            await nvim.input('za');
            return 'Toggled fold at cursor';
            
          case 'openall':
            await nvim.command('normal! zR');
            return 'Opened all folds';
            
          case 'closeall':
            await nvim.command('normal! zM');
            return 'Closed all folds';
            
          case 'delete':
            await nvim.input('zd');
            return 'Deleted fold at cursor';
            
          default:
            throw new NeovimValidationError(`Unknown fold action: ${action}`);
        }
      } catch (error) {
        if (error instanceof NeovimValidationError) {
          throw error;
        }
        console.error('Error managing fold:', error);
        throw new NeovimCommandError(`fold ${action}`, error instanceof Error ? error.message : 'Unknown error');
      }
    }
  • src/index.ts:538-563 (registration)
    MCP tool registration for 'vim_fold', including description, input schema, and thin wrapper handler that delegates to NeovimManager.manageFold.
    server.tool(
      "vim_fold",
      "Manage code folding: create, open, close, and toggle folds",
      {
        action: z.enum(["create", "open", "close", "toggle", "openall", "closeall", "delete"]).describe("Folding action to perform"),
        startLine: z.number().optional().describe("Start line for creating fold (required for create)"),
        endLine: z.number().optional().describe("End line for creating fold (required for create)")
      },
      async ({ action, startLine, endLine }) => {
        try {
          const result = await neovimManager.manageFold(action, startLine, endLine);
          return {
            content: [{
              type: "text",
              text: result
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: error instanceof Error ? error.message : 'Error managing fold'
            }]
          };
        }
      }
  • Zod input schema defining parameters for the vim_fold tool: action (enum of fold operations), optional startLine and endLine for manual folds.
    {
      action: z.enum(["create", "open", "close", "toggle", "openall", "closeall", "delete"]).describe("Folding action to perform"),
      startLine: z.number().optional().describe("Start line for creating fold (required for create)"),
      endLine: z.number().optional().describe("End line for creating fold (required for create)")
Behavior2/5

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

No annotations are provided, so the description carries full burden. While 'manage code folding' implies mutation operations, it doesn't disclose important behavioral details: whether folds persist across sessions, what happens when creating overlapping folds, whether operations are undoable, or what visual feedback to expect. For a tool with multiple actions including 'delete,' more behavioral context is needed.

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 extremely concise (7 words) and front-loaded with the core purpose. Every word earns its place: 'Manage code folding' establishes scope, and the action list specifies capabilities without redundancy. No wasted words or unnecessary elaboration.

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?

For a tool with 3 parameters (one required), no annotations, and no output schema, the description is insufficient. It doesn't explain what 'managing' entails operationally, what the tool returns, or how folding integrates with Vim's editing model. The agent would need to guess about important contextual aspects of folding behavior.

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 already documents all parameters thoroughly. The description mentions 'create' which implies startLine/endLine parameters, but adds no additional semantic context beyond what the schema provides. The baseline of 3 is appropriate when the schema does the heavy lifting.

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 tool's purpose as managing code folding with specific actions (create, open, close, toggle). It distinguishes from sibling tools by focusing on folding operations rather than buffers, commands, searches, etc. However, it doesn't explicitly differentiate from all siblings (e.g., vim_visual might also involve folding).

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 no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, when folding is appropriate, or how it relates to other Vim operations. With many sibling tools available, this lack of context leaves the agent guessing about appropriate usage scenarios.

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