Using End/Home keys to perfection in on Mac OS X

This guide is meant to help you out with changing terminal settings to get default linux like functionality of page up/down and home/end keys on Mac OS X.

I would suggest getting your terminal to behave properly first, so swap some keys in 'Terminal', 'Window Settings...', 'Keyboard', namely the 'end' and 'shift end', 'home' and 'shift home', 'page down' and 'shift page down' and 'page up' and 'shift page up'.

Then edit the home key: delete all that is there and type the following keys:
ctrl + [, [, 1, ~ it should now say: \033[1~
Do the same for the end key, it should say: \033[4~

Then setup those keys to have, linux like, sane behaviour in bash and other readline aware programs, as root edit /etc/inputrc or as user ~/.inputrc:

# Be 8 bit clean.
set input-meta on
set output-meta on
set convert-meta off

# allow the use of the Home/End keys
"\e[1~": beginning-of-line
"\e[4~": end-of-line

# allow the use of the Delete/Insert keys
"\e[3~": delete-char
"\e[2~": quoted-insert

# mappings for "page up" and "page down" to step to the beginning/end
# of the history
"\e[5~": beginning-of-history
"\e[6~": end-of-history

# alternate mappings for "page up" and "page down" to search the history
# "\e[5~": history-search-backward
# "\e[6~": history-search-forward

In the same arena, you can setup all your Cocoa Mac OS X programs to have the same behaviour with end / home / page up / page down keys, create a file ~/Library/KeyBindings/DefaultKeyBinding.dict that holds these values:

/* Changes home/end keys to a sane behaviour */
"\UF729" = "moveToBeginningOfLine:"; /* home */
"\UF72B" = "moveToEndOfLine:"; /* end */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* shift + home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* shift + end */

/* Changes pgup/pgdn keys to sane behaviour */
"\UF72C" = "pageUp:"; /* pgup */
"\UF72D" = "pageDown:"; /* pgdn */
"$\UF72C" = "pageUpAndModifySelection:"; /* shift + pgup */
"$\UF72D" = "pageDownAndModifySelection:"; /* shift + pgdn */

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


That was way more work than i thought it might have been. Thank you for saving some time!

Anonymous (not verified) – Wed, 2007 – 05 – 16 14:07

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
More information about formatting options Captcha Image: you will need to recognize the text in it.
Please type in the letters/numbers that are shown in the image above.