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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
improvement: add vim go-to-definition (gd) (#1862)
Myles Scolnick33766c953863
diff --git a/docs/guides/editor_features.md b/docs/guides/editor_features.mdindex 082dcf393e..b4eddb96f0 100644--- a/docs/guides/editor_features.md+++ b/docs/guides/editor_features.md@@ -137,6 +137,15 @@ A non-exhausted list of settings:- Autoreloading/Hot-reloading- Outputs above or below code cells+## Vim Support++marimo supports vim keybindings. Enable them in the settings menu.++**Additional bindings/features:**++- `gd` - go to definition+- `dd` - when a cell is empty, delete it+## Send feedbackThe question mark icon in the panels tray (lower left of the editor) opens adiff --git a/frontend/src/core/codemirror/keymaps/keymaps.ts b/frontend/src/core/codemirror/keymaps/keymaps.tsindex 1c5dfdddc1..d92a16ea52 100644--- a/frontend/src/core/codemirror/keymaps/keymaps.ts+++ b/frontend/src/core/codemirror/keymaps/keymaps.ts@@ -4,7 +4,7 @@ import { logNever } from "@/utils/assertNever";import { defaultKeymap } from "@codemirror/commands";import { type Extension, Prec } from "@codemirror/state";import { type EditorView, keymap } from "@codemirror/view";-import { vim, Vim } from "@replit/codemirror-vim";+import { vim } from "@replit/codemirror-vim";import { vimKeymapExtension } from "./vim";export const KEYMAP_PRESETS = ["default", "vim"] as const;@@ -33,10 +33,6 @@ export function keymapBundle(]),];case "vim":- // Delete a cell with :dcell- Vim.defineEx("dcell", "dcell", () => {- callbacks.deleteCell();- });return [// delete the cell on double press of "d", if the cell is emptyPrec.highest(diff --git a/frontend/src/core/codemirror/keymaps/vim.ts b/frontend/src/core/codemirror/keymaps/vim.tsindex 45b36d712d..29384d68dc 100644--- a/frontend/src/core/codemirror/keymaps/vim.ts+++ b/frontend/src/core/codemirror/keymaps/vim.ts@@ -1,6 +1,6 @@/* Copyright 2024 Marimo. All rights reserved. */-import { getCM, Vim } from "@replit/codemirror-vim";+import { CodeMirror, getCM, Vim } from "@replit/codemirror-vim";import { type EditorView, keymap, ViewPlugin } from "@codemirror/view";import {isAtEndOfEditor,@@ -10,11 +10,15 @@ import {import { invariant } from "@/utils/invariant";import type { Extension } from "@codemirror/state";import { Logger } from "@/utils/Logger";+import { goToDefinitionAtCursorPosition } from "../go-to-definition/utils";+import { once } from "@/utils/once";export function vimKeymapExtension(callbacks: {focusUp: () => void;focusDown: () => void;}): Extension[] {+ addCustomVimCommandsOnce();+return [keymap.of([{@@ -51,6 +55,15 @@ export function vimKeymapExtension(callbacks: {];}+const addCustomVimCommandsOnce = once(() => {+ // Go to definition+ Vim.defineAction("goToDefinition", (cm: CodeMirror) => {+ const view = cm.cm6;+ return goToDefinitionAtCursorPosition(view);+ });+ Vim.mapCommand("gd", "action", "goToDefinition", {}, { context: "normal" });+});+class CodeMirrorVimSync {private instances = new Set<EditorView>();private isBroadcasting = false;