日本語

@vimee/shiki-editor

Syntax-highlighted Vim editor powered by Shiki

A full-featured Vim editor component with syntax highlighting powered by Shiki.

Installation

npm install @vimee/core @vimee/react @vimee/shiki-editor shiki

Usage

import { use } from "react";
import { Vim } from "@vimee/shiki-editor";
import { createHighlighter } from "shiki";
import "@vimee/shiki-editor/styles.css";

const highlighterPromise = createHighlighter({
  themes: ["github-dark"],
  langs: ["typescript"],
});

function App() {
  const highlighter = use(highlighterPromise);

  return (
    <Vim
      content="const hello = 'world';"
      highlighter={highlighter}
      lang="typescript"
      theme="github-dark"
      onChange={(content) => console.log(content)}
    />
  );
}

Props

PropTypeDefaultDescription
contentstring(required)Editor content
highlighterHighlighterGeneric(required)Shiki highlighter instance
langstring(required)Language identifier
themestring(required)Shiki theme name
shikiOptionsRecord<string, unknown>Extra Shiki options
cursorPositionstring"1:1"Initial cursor (1-based)
onChange(content: string) => voidContent change callback
onYank(text: string) => voidYank callback
onSave(content: string) => voidSave callback
onModeChange(mode: VimMode) => voidMode change callback
onAction(action: VimAction, key: string) => voidAction callback
classNamestringContainer CSS class
readOnlybooleanfalseDisable editing
autoFocusbooleanfalseAuto-focus on mount
indentStyle"space" | "tab""space"Indent character
indentWidthnumber2Indent width
showLineNumbersbooleantrueShow line numbers

Sub-components

The package also exports individual sub-components for custom layouts:

  • <Cursor /> — Renders the editor cursor
  • <Line /> — Renders a single highlighted line
  • <StatusLine /> — Renders the Vim status bar

Hooks

  • useShikiTokens(highlighter, content, lang, theme, extraOptions?) — Tokenize content with Shiki
  • computeSelectionInfo(cursor, visualAnchor, buffer) — Compute visual selection ranges

CSS

Import the base styles:

import "@vimee/shiki-editor/styles.css";