Vim mode plugin (VM1–VM5) #538

Closed
opened 2026-10-17 16:39:21 +00:00 by kayg · 3 comments
Owner

Decided by kayg on 2026-10-16. The design was settled but no work had started; this issue tracks it.

  • VM1: a plugin, off by default, turned on in Settings.
  • VM2:
    • Esc enters normal mode; Esc in normal mode does nothing.
    • v = character-wise visual mode.
    • V = BLOCK selection (the approved block-selection look).
    • Ctrl-v = column selection.
    • Text objects (iw, i", is, it) work as in Vim.
  • VM3: as many Vim motions as make sense.
  • VM4: the caret's shape shows the mode.
  • VM5: off on phones and tablets without a hardware keyboard.

Related bug: Esc today selects the block's TEXT, which looks identical to a text selection.

🤖 Generated with Claude Code

Decided by kayg on 2026-10-16. The design was settled but no work had started; this issue tracks it. - **VM1:** a plugin, off by default, turned on in Settings. - **VM2:** - Esc enters normal mode; Esc in normal mode does nothing. - `v` = character-wise visual mode. - `V` = BLOCK selection (the approved block-selection look). - Ctrl-v = column selection. - Text objects (iw, i", is, it) work as in Vim. - **VM3:** as many Vim motions as make sense. - **VM4:** the caret's shape shows the mode. - **VM5:** off on phones and tablets without a hardware keyboard. Related bug: Esc today selects the block's TEXT, which looks identical to a text selection. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

Progress (branch issue/538-vim).

Research:

  • @replit/codemirror-vim 6.4.0 (MIT) came out on npm on 2026-07-29. The Vim engine now lives in @replit/codemirror-vim-core 0.1.0. Its peer dependencies are @codemirror/* 6.x, which we're on (view 6.43, state 6.7), and it adds @codemirror/search 6.7.2. It's maintained, and we're using it.
  • It needed fitting to our editor:
    • Undo: its u and Ctrl-r call CodeMirror's own history, and we have none (ADR 0022: Y.UndoManager). I rewired them to the shared history.
    • Its it text object needs an HTML tag tree, which markdown doesn't have. I wrote a text-based finder for it.
    • Its dialog panel became our bar's command line.
    • Its own edits are marked as typing, which would open the [[ picker. They're now marked as Vim's.
    • It records remote edits made during insert mode into .. Those are now skipped.
    • Its gg and k could land in the hidden properties. The first line is now the first one you can see.
  • It's loaded with import() only when Vim is on, so the main bundle doesn't change size.

Building now: the plugin in packages/editor/src/vim/, the Settings toggle, the bar command line (:, /, ?), the block look for Esc and V, and e2e/vim.spec.ts.

🤖 Generated with Claude Code

**Progress (branch `issue/538-vim`).** Research: - `@replit/codemirror-vim` 6.4.0 (MIT) came out on npm on 2026-07-29. The Vim engine now lives in `@replit/codemirror-vim-core` 0.1.0. Its peer dependencies are `@codemirror/*` 6.x, which we're on (view 6.43, state 6.7), and it adds `@codemirror/search` 6.7.2. It's maintained, and we're using it. - It needed fitting to our editor: - Undo: its `u` and Ctrl-r call CodeMirror's own history, and we have none (ADR 0022: Y.UndoManager). I rewired them to the shared history. - Its `it` text object needs an HTML tag tree, which markdown doesn't have. I wrote a text-based finder for it. - Its dialog panel became our bar's command line. - Its own edits are marked as typing, which would open the `[[` picker. They're now marked as Vim's. - It records remote edits made during insert mode into `.`. Those are now skipped. - Its gg and k could land in the hidden properties. The first line is now the first one you can see. - It's loaded with `import()` only when Vim is on, so the main bundle doesn't change size. Building now: the plugin in `packages/editor/src/vim/`, the Settings toggle, the bar command line (`:`, `/`, `?`), the block look for Esc and `V`, and `e2e/vim.spec.ts`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

Gate for PR #566 (issue/538-vim at 3a71b7a, --workers=1 through build-slot, host load about 35 on 12 cores):

Specs: vim, editor, touch-select, bar-focus, bar-rest, bar-stable, bar-stays, bar-taps, links and missing-links.

chromium-1440:  2 failed  38 skipped  49 passed (4.1m) 
  ✘  50 [chromium-1440] › e2e/missing-links.spec.ts:128:1 › a note in the Trash: a trash icon, and a card with its first lines, Restore and Open (21.5s)
  ✘  79 [chromium-1440] › e2e/vim.spec.ts:163:3 › Vim mode › motions, with counts (5.1s)
chromium-390:  19 skipped  70 passed (5.4m) 
webkit-1440:  1 failed  41 skipped  47 passed (7.6m) 
  ✘  79 [webkit-1440] › e2e/vim.spec.ts:163:3 › Vim mode › motions, with counts (8.1s)
  • Vim motions: that failure was the test's own expectation (h l l from column 0 lands on "pha"). Fixed.
  • missing-links trash card: this test doesn't touch Vim. A rerun on its own passed 3 out of 3 (--repeat-each 3).

Reruns after the fix:

chromium-1440:  1 skipped  13 passed (55.7s) 
webkit-1440:  2 skipped  12 passed (2.1m) 
chromium-1440:  3 passed (27.7s) 

(The first two lines are vim.spec on chromium-1440 and webkit-1440. The last is missing-links.spec.ts:128 --repeat-each 3.)

Other checks:

  • Editor unit tests: Test Files 19 passed (19) Tests 145 passed (145)
  • tsc --noEmit (packages/editor): 0 errors.
  • svelte-check: 1792269664109 COMPLETED 567 FILES 0 ERRORS 12 WARNINGS 7 FILES_WITH_PROBLEMS (the same 12 warnings as dev, all in files this PR doesn't touch).
  • Bundle sizes:
dev this PR
first_js_brotli (budget ≤ 240) 230 KB 233 KB
all_js_brotli (budget ≤ 260) 246 KB 249 KB
plugins_js_brotli, the Vim chunk (new budget ≤ 45) – 37.7 KB
first_css_brotli (budget 22.1) 23.7 KB 23.8 KB

first_css_brotli was already over its budget on dev.

Typing latency, Vim on and off (chromium-1440, the same 200-paragraph note, the same machine):

  • Keystroke to paint (@perf, PERF=1 --repeat-each 3). The host was loaded, so these are noise, not a gate:

    • off, default mode, p95: 611, 668, 1077 ms
    • off, source mode, p95: 757, 1394, 725 ms
    • Vim on, insert mode, p95: 543, 611, 488 ms
  • CPU per keystroke (a CDP profile over 600 keystrokes, alternating off and on):

    • total main-thread work: 5.98 and 6.68 ms off, 6.90 and 6.51 ms on;
    • Vim's own code: 0.22 ms per key.

    There's no measurable regression. The latency probe now runs first among the key handlers, so Vim's own key time counts.

Motions and commands covered by the tests:

  • Motions: h j k l, w b e, 0 $ ^, gg G, f t F T with ; and ,, %, and counts (2w, 3l, 2j, 3x, 2j on blocks).
  • Operators and edits: dw, ., x, 3x, cw, . after cw, dd, p, yy, P, o, O, cc, u, Ctrl-r.
  • Modes: v e d, V j k 2j Esc, V d with p back, Ctrl-v j l d.
  • Text objects: diw, ci", dis, dit.
  • Command line: / and ? with live highlights, n, N, Esc, :noh, :s, :%s (properties untouched), :3, :1, :w, an unknown command, :q.
  • Esc: Esc twice in normal mode does nothing. Esc with the [[ picker open closes it and stays in insert mode.
  • Caret: the block sits on the letter (within 1.5 px) in the accent, the outline shows in visual mode, and the insert caret is ≤ 3 px wide.
  • Elsewhere: remote edits while in normal mode (and u takes back only your own change), IME in insert mode, the Settings switch on and off, off on a touch-only screen (chromium-390), and the Esc block look with Vim off.
  • Unit tests: undo steps, the hidden properties, remote edits never joining ., V/j/k/d/p through DOM keys, :w, blocksIn and blockBeside, and it.

Open design questions for kayg:

  1. Insert or normal first? A note opens in insert mode, so typing just works and Esc gives normal mode. Vim itself opens in normal mode. Which do you want?
  2. Esc in normal mode does nothing (VM2), so with Vim on the keyboard can't leave the note by Esc. Today :q leaves it (on the desktop it blurs the editor, since there's always a note showing). Your 10-16 notes said "block mode = Esc twice or V". VM2 won here.
  3. The block look on the desktop is the #397 tint (16% accent, rounded, 8 px past the text). Your note also said "a soft accent ring". Should it have a ring too?
  4. Mouse drags across lines still look like selected words, though the bar shows the block bar. I only gave explicit block selections (Esc, the handle, V) the block look.
  5. The / block menu: there's no slash menu on dev. In insert mode / just types a slash, so a future slash menu will work there. In normal mode / is search.
  6. Ctrl shortcuts on Linux and Windows: in normal mode Vim's Ctrl keys win (Ctrl-b, d, e, r, v), so ⌘-style Ctrl shortcuts like Ctrl-b for bold work only in insert mode. In insert mode Vim keeps Ctrl-w, Ctrl-u, Ctrl-t, Ctrl-d and Ctrl-r. Ctrl-d (duplicate) is Vim's outdent there. On a Mac, ⌘ is never Vim's.
  7. :w says "Saved". You asked for this, but TASTE.md says never to show saving. Keep it?
  8. Bundle budget: I counted opt-in plugin chunks as a separate metric (web.bundle.plugins_*, budget ≤ 45 KB) rather than in all. Is that OK, or would you rather raise all_js_brotli?
  9. VM5 heuristic: a touch-only screen turns Vim on at the first Esc, arrow, Tab or modifier key. That first key itself still acts the non-Vim way.

🤖 Generated with Claude Code

**Gate for PR #566** (`issue/538-vim` at 3a71b7a, `--workers=1` through build-slot, host load about 35 on 12 cores): Specs: vim, editor, touch-select, bar-focus, bar-rest, bar-stable, bar-stays, bar-taps, links and missing-links. ``` chromium-1440: 2 failed 38 skipped 49 passed (4.1m) ✘ 50 [chromium-1440] › e2e/missing-links.spec.ts:128:1 › a note in the Trash: a trash icon, and a card with its first lines, Restore and Open (21.5s) ✘ 79 [chromium-1440] › e2e/vim.spec.ts:163:3 › Vim mode › motions, with counts (5.1s) chromium-390: 19 skipped 70 passed (5.4m) webkit-1440: 1 failed 41 skipped 47 passed (7.6m) ✘ 79 [webkit-1440] › e2e/vim.spec.ts:163:3 › Vim mode › motions, with counts (8.1s) ``` - **Vim motions:** that failure was the test's own expectation (`h l l` from column 0 lands on "pha"). Fixed. - **missing-links trash card:** this test doesn't touch Vim. A rerun on its own passed 3 out of 3 (`--repeat-each 3`). Reruns after the fix: ``` chromium-1440: 1 skipped 13 passed (55.7s) webkit-1440: 2 skipped 12 passed (2.1m) chromium-1440: 3 passed (27.7s) ``` (The first two lines are vim.spec on chromium-1440 and webkit-1440. The last is `missing-links.spec.ts:128 --repeat-each 3`.) Other checks: - Editor unit tests: ` Test Files 19 passed (19) Tests 145 passed (145)` - `tsc --noEmit` (packages/editor): 0 errors. - svelte-check: `1792269664109 COMPLETED 567 FILES 0 ERRORS 12 WARNINGS 7 FILES_WITH_PROBLEMS` (the same 12 warnings as dev, all in files this PR doesn't touch). - Bundle sizes: | | dev | this PR | |---|---|---| | `first_js_brotli` (budget ≤ 240) | 230 KB | 233 KB | | `all_js_brotli` (budget ≤ 260) | 246 KB | 249 KB | | `plugins_js_brotli`, the Vim chunk (new budget ≤ 45) | – | 37.7 KB | | `first_css_brotli` (budget 22.1) | 23.7 KB | 23.8 KB | `first_css_brotli` was already over its budget on dev. **Typing latency, Vim on and off** (chromium-1440, the same 200-paragraph note, the same machine): - **Keystroke to paint** (`@perf`, `PERF=1 --repeat-each 3`). The host was loaded, so these are noise, not a gate: - off, default mode, p95: 611, 668, 1077 ms - off, source mode, p95: 757, 1394, 725 ms - Vim on, insert mode, p95: 543, 611, 488 ms - **CPU per keystroke** (a CDP profile over 600 keystrokes, alternating off and on): - total main-thread work: 5.98 and 6.68 ms off, 6.90 and 6.51 ms on; - Vim's own code: 0.22 ms per key. There's no measurable regression. The latency probe now runs first among the key handlers, so Vim's own key time counts. **Motions and commands covered by the tests:** - **Motions:** h j k l, w b e, 0 $ ^, gg G, f t F T with ; and ,, %, and counts (2w, 3l, 2j, 3x, 2j on blocks). - **Operators and edits:** dw, `.`, x, 3x, cw, `.` after cw, dd, p, yy, P, o, O, cc, u, Ctrl-r. - **Modes:** v e d, V j k 2j Esc, V d with p back, Ctrl-v j l d. - **Text objects:** diw, ci", dis, dit. - **Command line:** `/` and `?` with live highlights, n, N, Esc, :noh, :s, :%s (properties untouched), :3, :1, :w, an unknown command, :q. - **Esc:** Esc twice in normal mode does nothing. Esc with the `[[` picker open closes it and stays in insert mode. - **Caret:** the block sits on the letter (within 1.5 px) in the accent, the outline shows in visual mode, and the insert caret is ≤ 3 px wide. - **Elsewhere:** remote edits while in normal mode (and `u` takes back only your own change), IME in insert mode, the Settings switch on and off, off on a touch-only screen (chromium-390), and the Esc block look with Vim off. - **Unit tests:** undo steps, the hidden properties, remote edits never joining `.`, V/j/k/d/p through DOM keys, `:w`, blocksIn and blockBeside, and `it`. **Open design questions for kayg:** 1. **Insert or normal first?** A note opens in **insert** mode, so typing just works and Esc gives normal mode. Vim itself opens in normal mode. Which do you want? 2. **Esc in normal mode does nothing (VM2),** so with Vim on the keyboard can't leave the note by Esc. Today `:q` leaves it (on the desktop it blurs the editor, since there's always a note showing). Your 10-16 notes said "block mode = Esc twice or V". VM2 won here. 3. **The block look on the desktop** is the #397 tint (16% accent, rounded, 8 px past the text). Your note also said "a soft accent ring". Should it have a ring too? 4. **Mouse drags across lines** still look like selected words, though the bar shows the block bar. I only gave explicit block selections (Esc, the handle, V) the block look. 5. **The `/` block menu:** there's no slash menu on dev. In insert mode `/` just types a slash, so a future slash menu will work there. In normal mode `/` is search. 6. **Ctrl shortcuts on Linux and Windows:** in normal mode Vim's Ctrl keys win (Ctrl-b, d, e, r, v), so ⌘-style Ctrl shortcuts like Ctrl-b for bold work only in insert mode. In insert mode Vim keeps Ctrl-w, Ctrl-u, Ctrl-t, Ctrl-d and Ctrl-r. Ctrl-d (duplicate) is Vim's outdent there. On a Mac, ⌘ is never Vim's. 7. **`:w` says "Saved".** You asked for this, but TASTE.md says never to show saving. Keep it? 8. **Bundle budget:** I counted opt-in plugin chunks as a separate metric (`web.bundle.plugins_*`, budget ≤ 45 KB) rather than in `all`. Is that OK, or would you rather raise `all_js_brotli`? 9. **VM5 heuristic:** a touch-only screen turns Vim on at the first Esc, arrow, Tab or modifier key. That first key itself still acts the non-Vim way. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

Closing during the 26 Oct handover cleanup: The Vim mode plugin landed in dev (PRs #566, #567).

Closing during the 26 Oct handover cleanup: The Vim mode plugin landed in dev (PRs #566, #567).
kayg closed this issue 2026-10-26 08:46:37 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal#538
No description provided.