Apple - Terminal problem with Ctrl + Arrow and Shift + Arrow keys

The same thing happens on my 10.9 and 10.8 VMs. Control-arrows and shift-arrows don't do anything by default in bash. Where were you even using shift-arrows to select text? emacs or vim?

If you want to use control-left and control-right to move between words in bash, add these lines to ~/.inputrc:

"\e[1;5C": forward-word
"\e[1;5D": backward-word

To use shift-arrows in Emacs, map shift-up to \e[1;2A, shift-down to \e[1;2B, shift-right to \e[1;2C, and shift-left to \e[1;2D. If pressing shift-up results in a message like <select> is undefined, try setting TERM to xterm-vt220.


Ctrl+Left/Right are present in Terminal (macOS 10.12) by default (Preferences → Profiles → Keyboard). I tried adding Shift-Up/Down in ~/.inputrc but nothing happened.

~/.inputrc:

"\e[1;2A": shift-up
"\e[1;2B": shift-down

Instead I added Shift Up/Down programatically in Terminal Preferences. The problem is that this is stored per profile, of which macOS has a dozen by default, so you have to loop over all the profiles (one named Ocean here) to add the keys for all available profiles. I don't know if plutil or defaults have some magic to make this easy, or if you have to use an XML parser.

~/Library/Preferences/com.apple.Terminal.plist:

"Window Settings" = {
  Ocean = {
    keyMapBoundKeys = {
      "$F700" = "\033[1;2A";
      "$F701" = "\033[1;2B";