Keybindings System
Complete keyboard shortcut customization for the terminal UI.
Overview
A full keyboard shortcut system with 20+ contexts, user-configurable bindings, chord support, and platform-aware resolution.
Architecture
Shared from "Claude-Code" on Inkdown
Complete keyboard shortcut customization for the terminal UI.
A full keyboard shortcut system with 20+ contexts, user-configurable bindings, chord support, and platform-aware resolution.
20+ binding contexts, each with its own keymap:
| Context | Scope |
|---|---|
| Global | Always active |
| Chat | When typing in the chat input |
| Autocomplete | When autocomplete is open |
| Confirmation | When confirmation dialog is shown |
| Help | When help panel is open |
| Transcript | When viewing transcript |
| HistorySearch | When searching history (ctrl+r) |
| Task | When task panel is focused |
| ThemePicker | When picking a theme |
| Settings | When in settings UI |
| Tabs | Tab navigation |
| Attachments | Attachment management |
| Footer | Footer item selection |
| MessageSelector | Message selection mode |
| DiffDialog | Diff viewer |
| ModelPicker | Model selection UI |
| Select | Generic select component |
| Plugin | Plugin management UI |
| Scroll | Scrollable content |
| MessageActions | Message action buttons |
Context-specific bindings override global bindings:
defaultBindings.ts)Core bindings shipped with the app:
Different bindings for macOS vs Windows:
Detects if running in a virtual terminal (vs SSH) and adjusts bindings accordingly.
Users customize bindings via keybindings.json:
Bindings are validated with Zod:
Multi-key chords are supported:
Keys can be bound to slash commands:
parser.ts)Parses keybinding strings into structured format:
match.ts)Matches a keypress against bindings:
Handles:
resolver.ts)Resolves the final binding for a keypress:
Priority:
validate.ts)Validates user keybindings:
Checks:
reservedShortcuts.ts)Shortcuts that cannot be overridden:
useKeybinding(action, callback)Subscribe to a keybinding:
useShortcutDisplay(action)Get the display string for a shortcut:
template.ts)Generates the default keybindings.json template:
shortcutFormat.ts)Formats keybindings for display:
| File | Purpose |
|---|---|
src/keybindings/defaultBindings.ts | Default key bindings |
src/keybindings/KeybindingContext.tsx | React context for keybindings |
src/keybindings/KeybindingProviderSetup.tsx | Provider initialization |
src/keybindings/loadUserBindings.ts | Load user keybindings.json |
src/keybindings/match.ts | Key matching logic |
src/keybindings/parser.ts | Key string parser |
src/keybindings/reservedShortcuts.ts | Reserved shortcuts |
src/keybindings/resolver.ts | Binding resolution |
src/keybindings/schema.ts | Zod validation schema |
src/keybindings/shortcutFormat.ts | Display formatting |
src/keybindings/template.ts | Template generation |
src/keybindings/useKeybinding.ts | useKeybinding hook |
src/keybindings/useShortcutDisplay.ts | Display hook |
src/keybindings/validate.ts | Validation logic |