Bash – How to bind Ctrl+arrows/backspace/del to the Readline commands

bashescape-charactersinputrckeyboard shortcutsreadline

I'm trying to make the following bindings in my ~/.inputrc:

(Ctrl+Del): kill-word
(Ctrl+Backspace): backward-kill-word
(Ctrl+forward arrow): forward-word
(Ctrl+back arrow): backward-word
(Home): beginning-of-line
(End): end-of-line

What actual key sequence notations should I use for those?

Best Answer

Something like this:

"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[H": beginning-of-line
"\e[F": end-of-line
"\eOH": beginning-of-line
"\eOF": end-of-line
"\e[1~": beginning-of-line
"\e[4~": end-of-line

Depending on the terminal settings and whether you're using screen, xterm would send those variations for Home and End, while the Control modified-cursor keys send a consistent value. You could change that (with xterm: other terminals generally not).

The control/Del and control/backspace probably won't work, unless by Del you mean the lower-left key on the 6-key editing keypad. For xterm, that sends "\e[3;5~".

With putty, you have few choices for "ctrlarrows" because it uses the control-modifier to switch between the normal and application modes of the cursor keys. That is, you'd toggle between "\e[C" (normal) and "\eOC" (application). Also, it's possible to change the home/end (to what putty's developers called "rxvt") to get the "\e[H" mentioned above.

Further reading: