日本語

@vimee/core

The core Vim engine — pure functions, zero dependencies

The core package provides the Vim engine as a collection of pure functions. No framework bindings, no UI — just the engine.

Installation

npm install @vimee/core

Key Concepts

TextBuffer

A mutable text buffer that manages content and undo history:

import { TextBuffer } from "@vimee/core";

const buffer = new TextBuffer("Hello, World!");

buffer.getContent();    // "Hello, World!"
buffer.getLine(0);      // "Hello, World!"
buffer.getLineCount();  // 1

VimContext

All Vim state is represented in a VimContext object:

import { createInitialContext } from "@vimee/core";

const ctx = createInitialContext({ line: 0, col: 0 });

// ctx.mode    — "normal", "insert", "visual", etc.
// ctx.cursor  — { line: 0, col: 0 }
// ctx.phase   — "idle", "operator-pending", etc.

Processing Keystrokes

Every keystroke is processed by a pure function that returns a new context and a list of actions:

import { processKeystroke } from "@vimee/core";

const { newCtx, actions } = processKeystroke("i", ctx, buffer);
// newCtx.mode === "insert"
// actions === [{ type: "mode-change", mode: "insert" }]

Actions

Actions describe what happened as a result of a keystroke:

import { actions } from "@vimee/core";

// Create actions programmatically
actions.cursorMove({ line: 0, col: 5 });
actions.modeChange("insert");
actions.contentChange("new content");
actions.statusMessage("-- INSERT --");

Motions and Operators

vimee supports standard Vim motions and operators:

// Motions: h, j, k, l, w, b, e, 0, $, gg, G, ...
// Operators: d, c, y, >, <
// Combined: dw, ci", yy, ...
const r1 = processKeystroke("d", ctx, buffer);
const r2 = processKeystroke("w", r1.newCtx, buffer); // delete word

Custom Keybindings

import { createKeybindMap } from "@vimee/core";

const keybinds = createKeybindMap();
// Use with processKeystroke's keybinds parameter