open_file
Open files in Neovim for editing. Use this tool to access existing files or newly created files by providing the file path.
Instructions
Open a file in Neovim. Use this to open newly created files or existing files for editing.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | The file path to open (can be absolute or relative to current directory) |
Implementation Reference
- lib/nvim-operations.js:243-269 (handler)Core implementation of the open_file tool: finds Neovim instance, converts path to absolute, and executes the 'edit' command to open the file.export async function openFile(filePath) { const instances = await getNvimInstancesInCwd(); if (instances.length === 0) { throw new Error("No Neovim instance found in current directory"); } // Use the first instance found const { nvim } = instances[0]; try { // Convert to absolute path if relative const absolutePath = path.isAbsolute(filePath) ? filePath : path.join(process.cwd(), filePath); // Open the file in nvim await nvim.command(`edit ${absolutePath}`); return { success: true, path: absolutePath, }; } catch (error) { throw new Error(`Failed to open file: ${error.message}`); } }
- index.js:189-202 (schema)Input schema definition for the 'open_file' tool requiring a 'path' parameter.name: "open_file", description: "Open a file in Neovim. Use this to open newly created files or existing files for editing.", inputSchema: { type: "object", properties: { path: { type: "string", description: "The file path to open (can be absolute or relative to current directory)", }, }, required: ["path"], },
- index.js:188-203 (registration)Registration of the 'open_file' tool in the ListToolsRequestSchema handler, including name, description, and schema.{ name: "open_file", description: "Open a file in Neovim. Use this to open newly created files or existing files for editing.", inputSchema: { type: "object", properties: { path: { type: "string", description: "The file path to open (can be absolute or relative to current directory)", }, }, required: ["path"], }, },
- index.js:298-308 (registration)Tool call dispatcher in CallToolRequestSchema handler that invokes the openFile function for 'open_file' tool.if (name === "open_file") { const result = await openFile(args.path); return { content: [ { type: "text", text: `Successfully opened file in Neovim: ${result.path}`, }, ], }; }
- index.js:18-19 (helper)Import of the openFile handler from lib/nvim-operations.js.openFile, } from "./lib/nvim-operations.js";