How to configure SHIFT+LEFT, SHIFT+RIGHT, SHIFT+HOME and SHIFT+END keys in terminal on Mac?

To configure the Home and End keys in terminal on MacBook Air (OS X 10.7.2) I defined in Terminal -> Preferences -> Keyboard:

Key     Action
----    ------
Home    \033OH
End     \033OF

What are the codes to configure the following combinations so that they will work like in Windows?

  • Shift+Left (should select the character on the left)
  • Shift+Right (should select the character on the right)
  • Shift+Home (should select all the characters on the left)
  • Shift+End (should select all the characters on the right)

You can use the read command to determine the keybinding sequence followed by your required keys

Add the output to the below file prefixed with "\e[your sequence]"

Create a file in your home directory ~/ called .inputrc

$ vim ~/.inputrc

I have the following setup for ctrl + left , right, up, down and home and end keys

"\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

Restart Terminal.app and your good to go.