codemirror vim
1.0.0
npm i @replit/codemirror-vim 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' ) ,
} )注意:如果您不使用
basicSetup,請確保包含Drawsection插件以在視覺模式下正確渲染選擇。
可以在CodeMirror view.cm版本中使用的API https://codemirror.net/doc/manual.html#vimapi也可以與此插件一起使用
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>" ) Vim . defineEx ( 'write' , 'w' , function ( ) {
// save the file
} ) ; Vim . map ( "jj" , "<Esc>" , "insert" ) ; // in insert mode
Vim . map ( "Y" , "y$" ) ; // in normal mode Vim . unmap ( "jj" , "insert" ) ; defaultKeymap . push ( { keys : 'gq' , type : 'operator' , operator : 'hardWrap' } ) ;
Vim . defineOperator ( "hardWrap" , function ( cm , operatorArgs , ranges , oldAnchor , newHead ) {
// make changes and return new cursor position
} ) ;