Keyboard & hotkeys
The core Terminal encodes VT keys and Kitty keyboard protocol sequences without forcing an opinionated shortcut table on your app. When you want Ghostty’s standard copy, clear, zoom, and scroll shortcuts, install the optional @shaulavo/hotkeys peer dependency and connect it with ghostty-webgpu/hotkeys.
You will learn
- How to attach Ghostty’s default shortcut map before opening a terminal
- Which macOS, Linux, and Windows shortcuts ship out of the box
How to override bindings, handle custom clipboards, or integrate with an app-wide hotkey dispatcher
Attach shortcuts before opening
Section titled “Attach shortcuts before opening”import { Terminal } from 'ghostty-webgpu'import { attachTerminalHotkeys } from 'ghostty-webgpu/hotkeys'
export async function mountHotkeys(host: HTMLElement) { const terminal = await Terminal.create() const connection = attachTerminalHotkeys(terminal, { mode: 'standalone', bindings: [{ keys: 'Ctrl+Q', command: 'terminal.clear', context: 'Terminal', source: 'user' }], }) await terminal.open(host) return () => { connection.dispose() terminal.dispose() }}Call attachTerminalHotkeys(terminal, options) before terminal.open(host). The adapter claims original keyboard input through terminal.connectInput() once the terminal opens, and disposing either the returned handle or the terminal cleans up listeners and aborts pending clipboard work. Only one original-input owner can attach to a terminal at a time.
Default Ghostty keymap
Section titled “Default Ghostty keymap”| Action | macOS | Linux and Windows |
|---|---|---|
| Copy selection | Cmd+C | Ctrl+Shift+C |
| Select all | Cmd+A | Ctrl+Shift+A |
| Clear above prompt | Cmd+K | Ctrl+Shift+K |
| Increase font size | Cmd+= | Ctrl+= |
| Decrease font size | Cmd+- | Ctrl+- |
| Reset font size | Cmd+0 | Ctrl+0 |
| Scroll to top or bottom | Cmd+Home, Cmd+End | Shift+Home, Shift+End |
| Scroll one page | Cmd+PageUp, Cmd+PageDown | Shift+PageUp, Shift+PageDown |
On macOS, Cmd+Left, Cmd+Right, Cmd+Backspace, Option+Left, and Option+Right forward standard shell line-editing actions (the shell must recognize them), while Option plus letter keys continue to compose dead-key characters.
A few intentional behaviors keep shortcuts predictable:
terminal.clearclears selection, scrollback, and rows above the cursor while keeping the active prompt row at the top; it is a no-op on the alternate screen.- Copy does nothing when nothing is selected, letting
Ctrl+Creach the shell as interrupt (^C). - Paste uses the browser’s native
pasteevent (honoring bracketed paste mode when active) so no default shortcut triggers a clipboard-read permission prompt.
Customize bindings or clipboards
Section titled “Customize bindings or clipboards”- Override or extend bindings: Pass
bindingsto layer custom shortcuts on top ofghosttyKeymap[platform](later bindings override earlier ones), or passkeymap: []to start from a blank slate. - Screen-reader compatibility: Pass
screenReaderMode: () => enabledto suspend the five macOS text-navigation shortcuts while a screen reader is active. - Custom clipboard environments:
navigator.clipboard.writeTextrequires a secure context and user gesture. In a desktop webview or custom host, passclipboard: { readText, writeText }andonErrorcallbacks.
Integrating with an existing @shaulavo/hotkeys dispatcher
Apps that already run @shaulavo/hotkeys can pass mode: ‘hosted’
alongside their dispatcher, parent focus node, and platform so terminal shortcuts participate
in global focus routing. You can also import ghosttyKeymap and
terminalShellKeysPack from ghostty-webgpu/hotkeys to inspect or
reuse the binding definitions. See
docs/hotkeys.md
for the focus adapter contract.
Recap
Call
attachTerminalHotkeys(terminal)beforeopen()on the main entry.Pass
bindingsto override defaults, orkeymap: []to define your own table from scratch.Use
mode: ‘hosted’when integrating terminal shortcuts into an application-wide@shaulavo/hotkeysdispatcher.