I am using these lines in my ~/.inputrc:

"\e[5~": history-search-backward
"\e[6~": history-search-forward

With these settings when I type c on the prompt and do a PageUp, bash only shows command starting with c from the history. PageDown does its inverse. I find this very much productive to me.

Without those lines in my inputrc file when I do Ctrl+Left, The cursor use to go to one word left and Ctrl+Left does its opposite. But with those setting mentioned above when I do Ctrl+Left and Ctrl+Right it prints ;5D and ;5C instead.

So how do I make Ctrl+Left & Ctrl+Right do the right stuff?

2 Answers 2


The two readline commands for these movements are forward-word and backward-word. You can access them, respectively, using (the default emacs binds): Altf and Altb.

To get then working using the Left and Right keys, you need to add a couple of lines to your ~/.inputrc.

First, confirm the correct escape sequences by getting the raw output from your terminal for those keypresses: enter Ctrlv CtrlLeft and Ctrlv CtrlRight and make note of the sequence (something like ^[Oc and ^[Od). Then append these lines to your .inputrc:

"\eOc": forward-word
"\eOd": backward-word

All of the readline commands can be rebound in your .inputrc.


note that those sequences may be different from one terminal to an other. From your text, it seems that you use gnome-terminal.

# on gnome-terminal
"\e[1;5D": backward-word
"\e[1;5C": forward-word

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .