# Vim mode in the prompt inputs

The /vim command writes the editor.vim_mode setting in config.json and signals the settings topic. The Web composer reads it through the Settings cache and the TUI through /api/settings. Both feed keys to the same state machine in apps/web/lib/vim/vim.ts, which returns text, cursor and mode; keys it declines go to the input's own bindings.

## Peers

| Harness | Turned on by | Starts in | Shown | Shape |
| --- | --- | --- | --- | --- |
| Codex CLI | `/vim` | INSERT | "Vim: Normal" / "Vim: Insert" in the footer | Modes, motions, operators, `.` repeat, replace mode, its own undo |
| Oh My Pi | `tui.vimMode` setting | INSERT | NORMAL / VISUAL / REPLACE in the status line; nothing for INSERT | A pure state machine returning edits; Enter, Tab and chords fall through to the host; an open popup takes Escape first; a quiet NORMAL hands Escape back |
| Claude Code | `/vim`, `editorMode` setting | INSERT | Mode under the prompt | Motions, operators, text objects, `.` |
| Antigravity CLI | `editorMode: "vim"` | NORMAL; INSERT with `vimInsertFirst` | Mode badge in the status line | Modes, Visual, motions, operators; also the review comment editors |
| Grok Build | `/vim-mode` | n/a | n/a | Vim keys for the scrollback, not the prompt |

Taken from Oh My Pi: the pure machine and its key rules. From Codex and Claude Code: `/vim` as the switch, `.` repeat and its own undo. From Codex: a label for both modes, so a person can tell at a glance that Vim mode is on.

## Design

| Part | Rule |
| --- | --- |
| Machine | `vimKey(state, {text, cursor}, key)` returns the new state and buffer and whether it took the key. No imports, no DOM, no terminal. The TUI imports the file through `apps/cli/src/utils/vim.ts` and esbuild bundles it. |
| INSERT | The input's own editing: the slash and file menus, paste chips, history recall and IME keep working. Only Escape is taken, unless a menu is open. |
| NORMAL | Every printable key is taken; an unknown one does nothing rather than typing. Enter, arrows, Tab and chords other than `Ctrl-r` stay with the input, so Enter sends in both modes as in every peer. |
| Escape | INSERT to NORMAL; in NORMAL it cancels a pending command, otherwise it goes to the input: the Web composer and the TUI stop a running turn. Idle, the TUI does nothing instead of clearing the draft as its plain Esc does. |
| Undo | The machine keeps its own snapshots, so the TUI, which has no undo, and the Web editor behave the same. One INSERT stretch is one step. A submit or a draft switch drops the history and returns to INSERT; the paste register stays. |
| `.` | The last change's keys, plus the text typed in its INSERT stretch, replayed on the current buffer; a count replaces the original one. |
| Setting | `editor.vim_mode`, a live toggle, off by default. `/vim` is a shared built-in (`openprogram/runtime/commands/vim_mode.py`) that writes it and signals the `settings` topic. The Web reads `/api/settings?scope=editor` through the Settings cache; the TUI reads it on connect, on a `changed` frame for `settings` and on the `/vim` reply. |
| Label | The only visual change. Web: the Nova Badge at the end of the input's first line, `accent` for NORMAL and `secondary` for INSERT. TUI: the mode at the right end of the input box after any hint, accent colour for NORMAL. Off, neither is drawn. |

## Implementation status

Implemented as described. Not included: Visual and replace modes, named registers, macros, search, `:` commands, text objects other than `iw aw iW aW`, insert counts (`3ix`), a block cursor in NORMAL, `j`/`k` history recall at the first or last line.
