npm i @replit/codemirror-vimimport{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 using
basicSetup, make sure you include the drawSelection plugin to correctly render the selection in visual mode.
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"letcm=getCM(view)// use cm to access the old cm5 apiVim.exitInsertMode(cm)Vim.handleKey(cm,"<Esc>")Vim.defineEx('write','w',function(){// save the file});Vim.map("jj","<Esc>","insert");// in insert modeVim.map("Y","y$");// in normal modeVim.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});