Skip to content

Keybindings

Magia has a built-in command registry. Every command has an ID, a category, a context, and an optional default key binding. Commands can be triggered from the Command Palette or via their keyboard shortcut.


Open the Command Palette with Cmd+K (macOS) / Ctrl+K (Linux/Windows). It shows all registered commands and lets you search and execute them by name. Commands that have a keybinding display it on the right side of the palette.


CommandIDDefault BindingContext
Command Paletteapp.command-paletteCmd+KGlobal
Open Settingsapp.settingsCmd+,Global
New Sessionapp.new-sessionCmd+NGlobal

These bindings are active when focus is inside the editor panel.

CommandIDDefault BindingContext
Save Fileeditor.saveCmd+SEditor
Undoeditor.undoCmd+ZEditor
Redoeditor.redoCmd+Shift+ZEditor
Findeditor.findCmd+FEditor
Find and Replaceeditor.replaceCmd+HEditor
CommandIDDefault BindingContext
Toggle Terminalterminal.toggleCmd+` Global
Clear Terminalterminal.clearCmd+KTerminal
CommandIDDefault BindingContext
Go Homenav.go-homeCmd+Shift+HGlobal
Go Backnav.go-backCmd+[Global

ContextActive when
globalAlways active throughout the app.
editorThe CodeMirror editor panel has keyboard focus.
terminalThe xterm.js terminal panel has keyboard focus.

Commands in the global context fire regardless of which panel is focused. Context-specific commands only fire when the relevant panel is active.


  1. Open Settings (Cmd+,).
  2. Navigate to Keybindings.
  3. Click the binding you want to change, then press the new key combination.
  4. Changes take effect immediately and are persisted automatically.

To reset a single binding to its default, click the reset icon next to it. To reset all bindings, use the Reset All button at the top of the keybindings panel.

Custom bindings are stored alongside settings in the app data directory. You can also edit them directly:

macOS:

~/Library/Application Support/sh.magia.com/keybindings.json

The file is a JSON object mapping command IDs to key combo objects:

{
"app.new-session": {
"key": "n",
"meta": true,
"ctrl": false,
"shift": true,
"alt": false
}
}
FieldTypeDescription
keystringThe key name (e.g. "k", "F1", "Escape", ",", "”`).
metabooleanCmd (macOS) / Win (Windows/Linux).
ctrlbooleanCtrl.
shiftbooleanShift.
altbooleanAlt / Option.

Restart is not required — the store picks up changes on next launch.


Magia uses a Zustand-based command registry (src/store/keybindings.ts). Commands are registered at app startup via registerDefaultCommands(). Plugins and feature modules can add their own commands by calling registerCommand() at any time.

import { useKeybindingsStore } from "@/store/keybindings";
useKeybindingsStore.getState().registerCommand({
id: "myfeature.do-thing",
label: "Do the Thing",
category: "My Feature",
context: "global",
defaultBinding: { key: "t", meta: true, ctrl: false, shift: false, alt: false },
});

Key APIs:

FunctionDescription
registerCommand(cmd)Register a new command. No-op if the ID already exists.
getEffectiveBinding(id)Returns the active binding (custom override or default).
setCustomBinding(id, combo)Store a custom binding for a command.
resetBinding(id)Remove the custom override, reverting to the default.
resetAllBindings()Remove all custom overrides.
detectConflicts(excludeId, combo, context, ...)Check if a combo conflicts with another command in the same context.