3.4 KiB
Keybindings vs. Keymappings
Make it keymappings, closer to neovim. Can be layered like <leader>abc. Commands don't define their binding, but have an id that a key can be mapped to like
{ key: "ctrl+w", cmd: string | function, description }
Why
Currently its keybindings that have an id like message_redo and then a command can use that or define it's own binding. While some keybindings are just used with .match in arbitrary key handlers and there is no info what the key is used for, except the binding id maybe. It also is unknown in which context/scope what binding is active, so a plugin like which-key is nearly impossible to get right.
OpenTUI Keymap Migration
The v2 TUI uses @opentui/keymap as the key/cmd engine. The remaining legacy compatibility is config-only and exists to migrate users from keybinds to keymap:
packages/opencode/src/config/keybinds.ts: oldkeybindsschema, defaults, and legacy key names.packages/opencode/src/cli/cmd/tui/config/legacy-keymap-transform.ts: transforms parsed legacykeybindsinto OpenTUIkeymapsections.packages/opencode/src/cli/cmd/tui/config/tui-migrate.ts: migrates legacy TUI keys fromopencode.jsonintotui.json, includingtheme,keybinds, and nestedtui.packages/opencode/src/cli/cmd/tui/config/tui-schema.ts: still accepts deprecatedkeybindsviaKeybindOverrideand marks it as deprecated. This file also contains the newkeymapconfig schema.packages/opencode/src/cli/cmd/tui/config/tui.ts: parses legacykeybinds, applies the Windowsterminal_suspend/input_undoadjustment, and usesLegacyKeymapTransform.create(...)as the fallback when nokeymapsection is configured.packages/plugin/src/tui.ts: plugin-facingtuiConfigstill includeskeybindsthroughPluginConfig; this should be removed when the public plugin API no longer exposes legacy config.
The transform must stay while users are migrating. It lets users upgrade without first rewriting their existing keybinds config. If keymap is configured, keybinds are ignored for keymap resolution. If keymap is missing, legacy-keymap-transform.ts turns legacy keybinds into the resolved keymap consumed by OpenTUI.
Removing Legacy Later
When switching fully to the new config style, remove legacy support with these exact changes:
- Delete
packages/opencode/src/config/keybinds.ts. - Delete
packages/opencode/src/cli/cmd/tui/config/legacy-keymap-transform.ts. - Delete
packages/opencode/src/cli/cmd/tui/config/tui-migrate.ts. - In
packages/opencode/src/cli/cmd/tui/config/tui-schema.ts, remove theConfigKeybindsimport, removeKeybindOverride, and delete the deprecatedkeybindsfield fromTuiInfo. - In
packages/opencode/src/cli/cmd/tui/config/tui.ts, removemigrateTuiConfig(...), removeConfigKeybinds, remove the Windows legacy keybind adjustment, removeLegacyKeymapTransform.create(...), and require/defaultkeymapthrough the new config path instead. - In
packages/opencode/src/cli/cmd/tui/config/tui.ts, removekeybindsfromResolved; resolved TUI config should exposekeymaponly. - In
packages/plugin/src/tui.ts, removekeybindsfrom plugin-facingTuiConfigView. - Remove or rewrite tests that write or assert
keybinds, especially inpackages/opencode/test/config/tui.test.ts,packages/opencode/test/fixture/tui-runtime.ts, and TUI plugin loader tests.