I am a huge fan of this magic in my .inputrc which allow me to quickly autocomplete a command with the up arrow key.

"\e[A": history-search-backward
"\e[B": history-search-forward
"\eOA": history-search-backward
"\eOB": history-search-forward

However very often, I have to ssh on a vanilla linux where I have to use CTRL+R. I then usually became very unproductive because I don't know how to use this command.

It is time to question my workflow. Can I be more productive by using the native bash history reverse search than my .inputrc magic?

Concrete use case

I would like to recall the last python line I have written. With my solution I do pyt+ + Enter

With the reverse-i-search, if I do CTRL + R, pyt. I usually get any command containing pyt, not the last command starting with python.

More annoying, I usually realize I should use my history when I already typed let's say pyth. If I hit CTRL + R I get:

(reverse-i-search)`': pyth

Which is very confusing because if I type o I suddenly get a WTF command I typed ages ago containing just a o.

I am totally sure I am not using the reverse-i-search the right way. What am I missing?


Are you using additional CTRL + R keystrokes to go beyond the first match?

In your example above, when you hit pyth you can then continue matching further back with additional CTRL + R presses.

Is that what you were looking for?

Update: Added example below, as requested.

Example: I want to match the older of these two similar commands.

$ python -m this
# ... snip...

$ python -c "import this"
# ... snip...

Now when you:

  1. CTRL + R
  2. Start typing pyt

At this point you have matched the latter of the two commands. Not the one you want (in this example).

  1. Hit CTRL + R one more time

At this point you will be matching the command you desire.

  • Do you have an example? – nowox Feb 28 at 8:54
  • Does that example help? – Guy Hoozdis Feb 28 at 9:01
  • @nowax, If that is not what you were looking for, then maybe you could clarify and I'll see what I can do. Best of luck. – Guy Hoozdis Mar 4 at 21:40

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.