Fix Page Up/Down, Home, End in Terminal

By default, if you press Page Up/Down, Home, or End in the Terminal, you will see less-than-helpful characters appear.  Here’s how to fix it:

Step 1 (Configure Terminal):

Open Preferences (Command+,) and go to Settings, Keyboard

To change a key, find it in the list and hit “Edit” (or “+” if it’s not in the list).  Change the action to “Send string to shell:” and use the following keycodes. IMPORTANT NOTE: Use the escape key (“esc”) for \033, do not enter it as text.

Page Up \033[5~
Page Down \033[6~
Home \033[1~
End \033[4~

You may also want to set Shift Page Up/Down to “scroll to previous/next page in buffer”

Borrowed from

Step 2 (Configure bash, optional):

You’ll need a correct /etc/inputrc (file may not already exist). Again, you may make this user-specific if you put it in ~/.inputrc instead.

"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": history-search-backward
"\e[6~": history-search-forward
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
set completion-ignore-case On

Step 3 (Set correct permissions):

You should set the correct permissions and ownership for security reasons:

For files in /etc

$ sudo chown root:staff /etc/bashrc /etc/inputrc
$ sudo chmod 644 /etc/bashrc /etc/inputrc

Or alternatively for files in ~

$ chmod 644 ~/.bashrc ~/.inputrc

post to facebookadd to del.icio.usAdd to Blinkslistadd to furlDigg itadd to ma.gnoliaStumble It!add to simpyseed the vineTailRank


3 Responses to Fix Page Up/Down, Home, End in Terminal

  1. […] Like the Terminal and bash, python does not have any good keyboard shortcuts enabled.  Following my earlier instructions will allow you to use page up/down for history by completion (i.e. you can type “x=” […]

  2. Thomas says:

    Thank you! This helped my a lot to finally get rid of these annoying limitations.

  3. Clemmie says:

    I am not sure where you’re getting your info, but good
    topic. I needs to spend some time learning much more or understanding more.
    Thanks for wonderful information I was looking for this info
    for my mission.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: