abhirampai / codemirror-vim

Vim keybindings for CM6

Home Page:https://www.npmjs.com/package/@replit/codemirror-vim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vim keybindings for CM6

Run on Replit badge NPM version badge

Installation

npm i @replit/codemirror-vim

Usage

import { basicSetup, EditorView } from 'codemirror';
import { vim } from "@replit/codemirror-vim"

let view = new EditorView({
  doc: "",
  extensions: [
    // make sure vim is included before other keymaps
    vim(), 
    // include the default keymap and all other keymaps you want to use in insert mode
    basicSetup, 
  ],
  parent: document.querySelector('#editor'),
})

Usage of cm5 vim extension api

The same api that could be used in previous version of codemirror https://codemirror.net/doc/manual.html#vimapi, can be used with this plugin too, just replace the old editor instance with view.cm in your code

import {Vim, getCM} from "@replit/codemirror-vim"

let cm = getCM(view)
// use cm to access the old cm5 api
Vim.exitInsertMode(cm)
Vim.handleKey(cm, "<Esc>")

About

Vim keybindings for CM6

https://www.npmjs.com/package/@replit/codemirror-vim

License:MIT License


Languages

Language:JavaScript 89.4%Language:TypeScript 10.2%Language:HTML 0.4%Language:Nix 0.0%