Add custom keyboard shortcuts in Terminal

Jul 19, '10 07:30:00AM

Contributed by: asmeurer

In Terminal, under the Keyboard tab of a theme, you can add custom keyboard shortcuts. However, if you try to add a custom shortcut that types a modifier key, you will have some difficulty. This is because the entry form seemingly makes it impossible to enter a modifier key or the escaped octal number for it.

The way around this is to type a backslash \, which will enter \\. Then arrow key left and type a forward delete. This will delete one of the backslashes, allowing you use the remaining one as an escape. You can, for example, use \033 to emulate the Option key. Another option is to look up the octal value for the key you want in the table at this Wikipedia article, and type the corresponding control sequence. For example, option is ^[, or Control-[. It also turns out that this is the same as escape, so you can just press the esc key if you want Option.

So if you want option-left and option-right to act like they do in normal Mac OS X Cocoa text boxes, you can map option-left arrow and option-right arrow to \033b and \033f, respectively (see, this is actually two hints in one!).

Note: I encountered a bug where it wouldn't let me close the pull-down sheet. The solution is to click on the + beneath the sheet, like you are adding a new shortcut, and it will work and let you close that.

[crarko adds: I tested this, and it works as described. Remember on a laptop keyboard in order to type a forward delete you may need to use 'fn-delete' combination.]

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20100716230217548