Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.