Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Add custom keyboard shortcuts in Terminal Apps
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.]
    •    
  • Currently 2.64 / 5
  You rated: 2 / 5 (22 votes cast)
 
[15,741 views]  

Add custom keyboard shortcuts in Terminal | 4 comments | Create New Account
Click here to return to the 'Add custom keyboard shortcuts in Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Add custom keyboard shortcuts in Terminal
Authored by: krang on Jul 19, '10 09:58:41AM

The "\033" is actually the [esc] key... just press [esc] and [b] for the option cursor left.



[ Reply to This | # ]
Add custom keyboard shortcuts in Terminal
Authored by: asmeurer on Jul 19, '10 02:12:03PM

Yep. I mention this in the hint.



[ Reply to This | # ]
Add custom keyboard shortcuts in Terminal
Authored by: feold3 on Oct 23, '10 07:36:06AM

I came looking for this hint after it appeared in the November 2010 Macworld. It works as described, but not for the reasons described. For starters, \033 is not the control code for Option (as you stated), it is the control code for Escape.

When you create a keystroke shortcut in Terminal you select the primary key that will trigger the shortcut (an arrow key in this case) from the top drop-down, a modifier key (Option in this case) from the second drop-down, the desired action (Send to shell in this case) from the third drop-down, then you enter what it is you want to send to the shell in the text box. In most cases the "what to send" will be a control code. The control code for Escape-b (one word back) is \033b, and for Escape-f (one word forward) it is \033f.

What you are creating is a shortcut that says "When I press Option-left arrow, send Escape-b to the shell" and "When I press Option-right arrow, send Escape-f to the shell".

It isn't necessary to do the "backslash-left arrow-forward delete" shuffle in order to enter the control code for Escape in the text box, although that method is often described. Just press the Escape key. That isn't true for most other control codes, which do require the "backslash-left arrow-forward delete" shuffle.



[ Reply to This | # ]
Add custom keyboard shortcuts in Terminal
Authored by: asmeurer on Oct 23, '10 11:43:49AM

I think when I originally submitted this hint, I didn't notice that the escape key for option is exactly the same as for escape. Anyway, I think the method I describe will still be necessary if you want to enter some other special character (like a Null character or something, or, obviously, the forward delete character).

And I guess I will have to go buy a copy of the November 2010 MacWorld if my hint is appearing in there :)



[ Reply to This | # ]