vim_macro
Record, stop, and play Neovim macros using specific registers and counts to automate repetitive text editing tasks in your workflow.
Instructions
Record, stop, and play Neovim macros
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform with macros | |
| count | No | Number of times to play macro (default: 1) | |
| register | No | Register to record/play macro (a-z, required for record/play) |
Implementation Reference
- src/neovim.ts:786-820 (handler)Core handler implementation for vim_macro tool. Handles 'record', 'stop', and 'play' actions by sending appropriate Neovim input sequences (q<register>, q, @<register>).public async manageMacro(action: string, register?: string, count: number = 1): Promise<string> { try { const nvim = await this.connect(); switch (action) { case 'record': if (!register || register.length !== 1 || !/[a-z]/.test(register)) { throw new NeovimValidationError('Register must be a single letter a-z for recording'); } await nvim.input(`q${register}`); return `Started recording macro in register '${register}'`; case 'stop': await nvim.input('q'); return 'Stopped recording macro'; case 'play': if (!register || register.length !== 1 || !/[a-z]/.test(register)) { throw new NeovimValidationError('Register must be a single letter a-z for playing'); } const playCommand = count > 1 ? `${count}@${register}` : `@${register}`; await nvim.input(playCommand); return `Played macro from register '${register}' ${count} time(s)`; default: throw new NeovimValidationError(`Unknown macro action: ${action}`); } } catch (error) { if (error instanceof NeovimValidationError) { throw error; } console.error('Error managing macro:', error); throw new NeovimCommandError(`macro ${action}`, error instanceof Error ? error.message : 'Unknown error'); } }
- src/index.ts:481-507 (registration)Registers the vim_macro tool with MCP server, including schema definition and thin handler delegating to neovimManager.manageMacro.server.tool( "vim_macro", "Record, stop, and play Neovim macros", { action: z.enum(["record", "stop", "play"]).describe("Action to perform with macros"), register: z.string().optional().describe("Register to record/play macro (a-z, required for record/play)"), count: z.number().optional().describe("Number of times to play macro (default: 1)") }, async ({ action, register, count = 1 }) => { try { const result = await neovimManager.manageMacro(action, register, count); return { content: [{ type: "text", text: result }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : 'Error managing macro' }] }; } } );
- src/index.ts:484-487 (schema)Zod schema defining input parameters for vim_macro: action (enum: record/stop/play), optional register (string), optional count (number).{ action: z.enum(["record", "stop", "play"]).describe("Action to perform with macros"), register: z.string().optional().describe("Register to record/play macro (a-z, required for record/play)"), count: z.number().optional().describe("Number of times to play macro (default: 1)")