Change vim mode programmatically

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:

  1. user changes text
  2. when correct, update text in editor
  3. 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({...})

Option 2:

Vim.handleKey(, "<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