MacOS – Where to learn more about OSX terminal app keyboard settings codes

If you look at the Terminal->Preferences->Settings->Keyboard pane it displays how some keyboard keys and combinations map to shell strings.

The list seems really strange to me as it's missing a lot of combinations like Shift+F1 and it maps option+F1 and F6 to the same code. Also the codes shown look like ANSI escape sequences but the function key numbers (ones I checked) don't match up.

I'd like to find an explanation for these details and a reference for adding proper codes for missing combinations like Shift+F1. Thanks for your input

Best Answer

  • The mappings are different because Mac OS X is not a DOS, for which the web site you linked to was apparently written. The specific mappings were inherited from previous Unix/Linux terminal emulators, as is reflected in your options for what kind of terminal emulator you wish to appear:

    enter image description here

    As you can see for example here, mapping F6 to ^[[17~ is widespread consensus among terminal emulators.

    Terminal's Shift-F5 to Shift-F12 is equivalent to the VT220's F13 to F20.

    Terminal's Opt-F1 to Opt-F15 is equivalent to the VT220's F6 to F20, i.e. option "shifts" 5 keys to the right.

    I assume this mapping is the result of the desire both to be compatible with existing mappings, and to provide as close to a full 20-F-key keyboard as possible with only 12 or 15 F-keys on modern Macs.

    If you don't like these particular mappings, it's easy to change them in the settings dialog you already mentioned. Remember that you can map to pretty much arbitrary input (which is actually a pretty nic(h)e way to do Typinator/TextExpander-like keyboard shortcuts in Terminal):

    enter image description here

    If you prefer editing in a plain-text editor, you can export a Terminal setting via the cog icon, edit it (it's XML), and import it again.