Use modifier keys in Terminal shortcuts

Whitson Gordon
27 July, 2010
View more articles fromthe author

Terminal is inarguably useful, but it does have its annoying quirks. For example, there are lots of standard key combinations for moving the cursor that don’t work on the Terminal command line. reader asmeurer, however, found a way to create his own keyboard shortcuts for use in Terminal windows:

In Terminal, under the Keyboard tab of a theme (Preferences -> Settings), you can add custom keyboard shortcuts. However, if you try to add a shortcut that includes a modifier key, you will run into a problem: the entry form seems to make it impossible to enter that modifier or even the escaped octal number for it.

One way around this is to type a backslash (\) in the entry form. That will enter a double backslash (\\). Press the left arrow key and then the forward Delete key. This will delete one of the backslashes. The remaining one can then serve as an escape character. You could, for example, enter “033″ to emulate the Option key.

Another way to insert escaped characters is to look up the octal value for the key you want in the table at this Wikipedia article, find the corresponding control sequence, and type that in the entry box. So, for example, to enter the octal code for the Option key (\033), you’d press Control-[.

So let’s say you wanted Option-Left and Option-Right to act in Terminal the way they do in normal Mac OS X text boxes (skipping full words instead of one character at a time). You’d start by clicking on the Plus (+) button at the bottom of the keyboard tab. You’d then select Cursor Left or Cursor Right from the Key drop-down and Option from the Modifier list. Then, with the cursor in that entry box, you’d use either method above to insert the escape character, then type in “33b” or “33f” to get “\033b” (Option-Left) or “\033f” (Option-Right).

These particular shortcuts (Option-Left and Option-Right) are especially useful in Terminal. But there are any number of other keyboard shortcuts that could also be handy to have, which you can add using the same method. Remember also, that if you are on a laptop, you need to press fn-Delete to get a forward delete.

Leave a Comment

Please keep your comments friendly on the topic.

Contact us