17

I got this working before (I believe it was on a 15.10, I recently downgraded to the LTS 14.04).

According to this post the following should work

~ $ cat ~/.inputrc 
"\e[A":history-search-backward
"\e[B":history-search-forward

But when I save that .inputrc and open a new terminal, typing PageUp or PageDown just prints the tilde character ~ in the terminal, instead of doing the search.

Any help appreciated.

19

Try this in ~/.inputrc

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

and reopen terminal.

8

\e[A and \e[B are actually the Up and Down arrow keys. To test what a key is, run cat and then press the key:

$ cat
^[[A
^[[B

^[[5~
^[[6~

Those are , , Page Up and Page Down respectively. The ^[ stands for Esc, or \e in terms of .inputrc.

So, if you added \e[A and \e[B, you should be able to browse history using arrow keys. For Page Up and Page Down, use \e[5~ and \e[6~.

1
  • Wow! I have so often see these escape sequences in the terminal, wondering what they were. Even though I already use them in eg. .inputrc, I have never made the connection. Very useful tip, thanks. – marlar Jun 26 '18 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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