Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: Vim Ctrl+[ to Escape (#4361)

Myles Scolnick32e624928eb4
diff --git a/frontend/src/core/codemirror/keymaps/vim.ts b/frontend/src/core/codemirror/keymaps/vim.ts
index 015c2ef7f7..4c15de7114 100644
--- a/frontend/src/core/codemirror/keymaps/vim.ts
+++ b/frontend/src/core/codemirror/keymaps/vim.ts
@@ -52,6 +52,32 @@ export function vimKeymapExtension(): Extension[] {
},
},
]),
+ keymap.of([
+ {
+ // Ctrl-[ by default is to dedent
+ // But for Vim (on Linux), it should exit insert mode when in Insert mode
+ linux: "Ctrl-[",
+ run: (ev) => {
+ const cm = getCM(ev);
+ if (!cm) {
+ Logger.warn(
+ "Expected CodeMirror instance to have CodeMirror instance state",
+ );
+ return false;
+ }
+ if (!hasVimState(cm)) {
+ Logger.warn("Expected CodeMirror instance to have Vim state");
+ return false;
+ }
+ const vim = cm.state.vim;
+ if (vim.insertMode) {
+ Vim.exitInsertMode(cm, true);
+ return true;
+ }
+ return false;
+ },
+ },
+ ]),
ViewPlugin.define((view) => {
// Wait for the next animation frame so the CodeMirror instance is ready
requestAnimationFrame(() => {