Does anyone know how to change the vim mode programmatically? I’m using this extension.
I see it uses CM5 under the hood and calls CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
I don’t see a similar property/method in CM6. Here’s a demo of what I’m trying to do:
- user changes text
- when correct, update text in editor
- set mode back to normal mode

Another way this could be achieved would be to send native key events to CodeMirror i.e. send the Escape key.
The team behind that extension responded with two options:
Option 1:
import {Vim} from "@replit/codemirror-vim"
var view = new EditorView({...})
Vim.exitInsertMode(view.cm)
Option 2:
Vim.handleKey(_view.cm, "<Esc>")
Note: you may need to typecast .cm with (view as any).cm.
Source: How to programmatically change modes? · Issue #6 · replit/codemirror-vim · GitHub