Markdown Edit

Linux and Terminal Keyboard Bindings

Keyboard shortcuts on Linux pass through multiple translation layers—from hardware scancodes and XKB/Wayland compositors, to terminal emulators (such as Kitty or Chrome's hterm / Secure Shell), down to terminal multiplexers (tmux) and TUI applications.

Terminal Escape Sequences and Non-ASCII Key Combinations

Traditional Unix terminals communicate keystrokes over a pseudo-terminal (PTY) byte stream using ASCII and C0 control characters (0x00–0x1F). Because legacy control characters collapse several distinct physical keys into the same byte—for example, Tab and Ctrl+I both produce 0x09 (\t), while Enter and Ctrl+M both produce 0x0D (\r)—combinations like Ctrl+Tab or Ctrl+Shift+Tab have no standard ASCII control code.

To disambiguate modified keys without breaking legacy PTY compatibility, modern terminal emulators emit Control Sequence Introducer (CSI) sequences (such as xterm's modifyOtherKeys or the Kitty keyboard protocol):

Terminal Emulator Configuration

Kitty

In kitty.conf, arbitrary byte sequences can be emitted for any shortcut using send_text:

map ctrl+tab send_text all \x1b[1;5I
map ctrl+backspace send_text all \x17

Chrome Secure Shell (nassh / hterm)

Chrome's Secure Shell extension (iodihamcpbpeioajjeobimgagajmlibd) uses the hterm JavaScript terminal emulator.

Why Ctrl+Tab Fails by Default in hterm

In hterm's built-in keymap (hterm_keyboard_keymap.js), pressing Tab (keyCode 9) with Ctrl invokes onCtrlTab_:

As a result, remote applications like tmux only receive a standard Tab character unless overridden via hterm's custom keybindings preference.

Overriding Keybindings in nassh_preferences_editor.html

In Secure Shell's Options (chrome-extension://iodihamcpbpeioajjeobimgagajmlibd/html/nassh_preferences_editor.html) under Terminal Settings → Keyboard → Keyboard bindings/shortcuts (keybindings), map Ctrl+Tab to emit \x1b[1;5I:

{
  "Ctrl+Tab": "'\u001b[1;5I'"
}

Two details are essential when configuring hterm keybindings:

TMUX Key Bindings and display-popup Traps

Custom Escape Sequences via user-keys

When a terminal emulator emits a raw CSI sequence like \e[1;5I for Ctrl+Tab, tmux can register that sequence as a custom User0 key and bind it directly in ~/.tmux.conf:

set -s user-keys[0] "\e[1;5I"
bind-key -n User0 display-popup -E -w 95% -h 40% "tmux-window-popup.sh"

A common trap when binding a key to tmux display-popup -E "<command>" is that the popup frame flashes briefly and immediately closes.