vim_file_open
Open files directly into new buffers within Neovim using a specific filename path, streamlining file access during code editing.
Instructions
Open files into new buffers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes | Path to the file to open |
Implementation Reference
- src/index.ts:358-375 (handler)The inline handler function for the vim_file_open tool. It calls neovimManager.openFile(filename), formats the response as MCP content, and handles errors.async ({ filename }) => { try { const result = await neovimManager.openFile(filename); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : 'Error opening file' }] }; } }
- src/index.ts:355-357 (schema)Zod input schema defining the 'filename' parameter for the vim_file_open tool.{ filename: z.string().describe("Path to the file to open") },
- src/index.ts:352-376 (registration)MCP server.tool call that registers the vim_file_open tool with its description, schema, and handler function.server.tool( "vim_file_open", "Open files into new buffers", { filename: z.string().describe("Path to the file to open") }, async ({ filename }) => { try { const result = await neovimManager.openFile(filename); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : 'Error opening file' }] }; } } );
- src/neovim.ts:628-641 (helper)NeovimManager.openFile method: the core logic that connects to Neovim and executes the 'edit filename' command to open the file into a new buffer.public async openFile(filename: string): Promise<string> { if (!filename || filename.trim().length === 0) { throw new NeovimValidationError('Filename cannot be empty'); } try { const nvim = await this.connect(); await nvim.command(`edit ${filename}`); return `Opened file: ${filename}`; } catch (error) { console.error('Error opening file:', error); throw new NeovimCommandError(`edit ${filename}`, error instanceof Error ? error.message : 'Unknown error'); } }