Skip to content

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

hotkeys.ts
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.

ActionmacOSLinux and Windows
Copy selectionCmd+CCtrl+Shift+C
Select allCmd+ACtrl+Shift+A
Clear above promptCmd+KCtrl+Shift+K
Increase font sizeCmd+=Ctrl+=
Decrease font sizeCmd+-Ctrl+-
Reset font sizeCmd+0Ctrl+0
Scroll to top or bottomCmd+Home, Cmd+EndShift+Home, Shift+End
Scroll one pageCmd+PageUp, Cmd+PageDownShift+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.clear clears 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+C reach the shell as interrupt (^C).
  • Paste uses the browser’s native paste event (honoring bracketed paste mode when active) so no default shortcut triggers a clipboard-read permission prompt.
  • Override or extend bindings: Pass bindings to layer custom shortcuts on top of ghosttyKeymap[platform] (later bindings override earlier ones), or pass keymap: [] to start from a blank slate.
  • Screen-reader compatibility: Pass screenReaderMode: () => enabled to suspend the five macOS text-navigation shortcuts while a screen reader is active.
  • Custom clipboard environments: navigator.clipboard.writeText requires a secure context and user gesture. In a desktop webview or custom host, pass clipboard: { readText, writeText } and onError callbacks.
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) before open() on the main entry.

  • Pass bindings to override defaults, or keymap: [] to define your own table from scratch.

  • Use mode: ‘hosted’ when integrating terminal shortcuts into an application-wide @shaulavo/hotkeys dispatcher.