Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Vim keybindings for CM6

License

NotificationsYou must be signed in to change notification settings

replit/codemirror-vim

Repository files navigation

Run on Replit badgeNPM version badge

Installation

npm i @replit/codemirror-vim

Usage

import{basicSetup,EditorView}from'codemirror';import{vim}from"@replit/codemirror-vim"letview=newEditorView({doc:"",extensions:[// make sure vim is included before other keymapsvim(),// include the default keymap and all other keymaps you want to use in insert modebasicSetup,],parent:document.querySelector('#editor'),})

Note:if you are not usingbasicSetup, make sure you include thedrawSelection plugin to correctly render the selection in visual mode.

Usage of cm5 vim extension api

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

import{Vim,getCM}from"@replit/codemirror-vim"letcm=getCM(view)// use cm to access the old cm5 apiVim.exitInsertMode(cm)Vim.handleKey(cm,"<Esc>")

Define additional ex commands

Vim.defineEx('write','w',function(){// save the file});

Map keys

Vim.map("jj","<Esc>","insert");// in insert modeVim.map("Y","y$");// in normal mode

Unmap keys

Vim.unmap("jj","insert");

Add custom key

defaultKeymap.push({keys:'gq',type:'operator',operator:'hardWrap'});Vim.defineOperator("hardWrap",function(cm,operatorArgs,ranges,oldAnchor,newHead){// make changes and return new cursor position});

Credits

This plugin was originally authored by@mightyguava (Yunchi Luo) as part ofCodeMirror, before being extracted and maintained here.


[8]ページ先頭

©2009-2025 Movatter.jp