brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Ctrl-V shows the code a key really sends to your terminal

Terminal
~/tips/tip-terminal-ctrl-v-raw-key

^[[1;5C

Shows the raw escape sequence of any key, which you need for key bindings.

Key bindings in ~/.inputrc, zsh or tmux want the exact characters a key sends, like ^[[1;5C. You don’t have to guess them.

At an empty prompt, press Ctrl-V and then the key you care about. Readline calls this quoted insert: the next key is put on the line as it is, without being acted on. Escape shows up as ^[, so Ctrl-Right Arrow in most terminals looks like this:

^[[1;5C

That is the string you paste into a binding. In ~/.inputrc you write the escape as \e:

"\e[1;5C": forward-word
"\e[1;5D": backward-word

It works in zsh too, where the same trick is how people find the codes for bindkey. Press Ctrl-U afterwards to clear the junk off the line.

The code depends on the terminal app and its settings, so check it in the terminal you actually use. On a Mac, Option combinations send nothing useful until you turn on Use Option as Meta key, and Terminal and iTerm2 can be set to send different sequences for the same key. If a binding works on one machine and not on another, this is the first thing I would compare.

Further reading: Commands for changing text (GNU Bash manual), Readline init file syntax (GNU Bash manual)

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link