vim_buffer_switch
Quickly switch between buffers in Neovim using buffer numbers or filenames, streamlining navigation and enhancing productivity in text editing workflows.
Instructions
Switch between buffers by name or number
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| identifier | Yes | Buffer identifier - can be buffer number or filename/path |
Implementation Reference
- src/index.ts:300-324 (registration)Registers the 'vim_buffer_switch' MCP tool, including input schema and inline handler that calls NeovimManager.switchBufferserver.tool( "vim_buffer_switch", "Switch between buffers by name or number", { identifier: z.union([z.string(), z.number()]).describe("Buffer identifier - can be buffer number or filename/path") }, async ({ identifier }) => { try { const result = await neovimManager.switchBuffer(identifier); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : 'Error switching buffer' }] }; } } );
- src/neovim.ts:569-597 (handler)The core handler logic for switching Neovim buffers by number or name/path in NeovimManager classpublic async switchBuffer(identifier: string | number): Promise<string> { try { const nvim = await this.connect(); // If identifier is a number, switch by buffer number if (typeof identifier === 'number') { await nvim.command(`buffer ${identifier}`); return `Switched to buffer ${identifier}`; } // If identifier is a string, try to find buffer by name const buffers = await nvim.buffers; for (const buffer of buffers) { const bufName = await buffer.name; if (bufName === identifier || bufName.endsWith(identifier)) { await nvim.command(`buffer ${buffer.id}`); return `Switched to buffer: ${bufName}`; } } throw new NeovimValidationError(`Buffer not found: ${identifier}`); } catch (error) { if (error instanceof NeovimValidationError) { throw error; } console.error('Error switching buffer:', error); throw new NeovimCommandError(`buffer switch to ${identifier}`, error instanceof Error ? error.message : 'Unknown error'); } }
- src/index.ts:303-305 (schema)Zod schema defining the input parameter for the vim_buffer_switch tool{ identifier: z.union([z.string(), z.number()]).describe("Buffer identifier - can be buffer number or filename/path") },