Modify cursor movement keys in Terminal
Aug 24, '06 07:30:03AM
Contributed by: eykanal
The defacto standard in Terminal's shells is meta-b (backward) and meta-f (forward) for word-by-word movement. In every other Cocoa app, however, it's Option-left arrow and Option-right arrow. I wanted Terminal to behave the same way.
Terminal has a Keyboard page in the Terminal Inspector which allows you to map keys any way you want. For example, to make Option-left arrow move to the previous word, you only need to add a new key binding entry like the following:
- Open Terminal.
- Go to File > Show Info (or type Command-I) to bring up the Terminal Inspector.
- Select Keyboard from the drop-down menu at the top of the Inspector.
- Press Add.
- Set the following:
- Key = cursor left
- Modifier = option
- Action = send string to shell:
- Press Esc (this should insert the text \033 in the text box) and then press b.
- Press OK.
- Lastly, hit the Use Settings as Defaults button.
You want to do the same for option cursor right. Simply repeat the above, changing Key to cursor left, and instead of pressing b after pressing Esc, press f (the resultant string will be \033f).
You can also bind control left/right to begin/end of paragraph. The shell keys for these two actions are Control-A for beginning of paragraph, and Control-E for end of paragraph. Again, simply repeat the steps above, changing the Modifier to control, make sure the Key is set to cursor left, and instead of pressing Esc and b, simply press Control-A (the resultant string will be \001). That's all ... press OK, and you can do the same again with cursor right and Control-E. Remember to hit the Use Settings as Defaults button when you are done!
This is a summary of a more-detailed version of this hint available on the Textmate blog.
Comments (16)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20060822210246174