日本語

@vimee/react

React hooks and bindings for vimee

React bindings for vimee, providing the useVim hook for seamless integration.

Installation

npm install @vimee/core @vimee/react

useVim

The primary hook for integrating vimee into a React component:

import { useVim } from "@vimee/react";

function Editor() {
  const { content, cursor, mode, handleKeyDown } = useVim({
    content: "Hello, vimee!",
  });

  return (
    <div onKeyDown={handleKeyDown} tabIndex={0}>
      <pre>{content}</pre>
      <div>Mode: {mode} | Cursor: {cursor.line}:{cursor.col}</div>
    </div>
  );
}

Options

OptionTypeDefaultDescription
contentstring(required)Initial editor content
cursorPositionstring"1:1"Initial cursor position (1-based, "line:col")
readOnlybooleanfalseDisable editing
onChange(content: string) => voidCalled when content changes
onYank(text: string) => voidCalled on yank
onSave(content: string) => voidCalled on :w
onModeChange(mode: VimMode) => voidCalled on mode change
onAction(action: VimAction, key: string) => voidCalled on every action
indentStyle"space" | "tab""space"Indent character
indentWidthnumber2Indent width
keybindsKeybindEntry[]Custom keybindings
commandsCommandEntry[]Custom ex-commands

Return Value

FieldTypeDescription
contentstringCurrent buffer content
cursorCursorPositionCurrent cursor (0-based)
modeVimModeCurrent Vim mode
statusMessagestringStatus bar message
statusErrorbooleanWhether status is an error
visualAnchorCursorPosition | nullVisual mode anchor
commandLinestringEx command being typed
handleKeyDown(e: React.KeyboardEvent) => voidAttach to onKeyDown
handleScroll(direction, visibleLines, amount?) => voidScroll handler
updateViewport(topLine, height) => voidViewport sync