159

I use reverse-i-search often, and that's cool. Sometime though when pressing CTRL+r multiple times, I pass the command I am actually looking for. Because CTRL+r searches backward in history, from newest to oldest, I have to:

  1. cancel,
  2. search again and
  3. stop exactly at the command, without passing it.

While in reverse-i-search prompt, is it possible to search forward, i.e. from where I stand to newest. I naively tried CTRL+Shift+r, no luck. I heard about CTRL+g but this is not what I am expecting here. Anyone has an idea?

simhumileco
  • 31,877
  • 16
  • 137
  • 115
m-ric
  • 5,621
  • 7
  • 38
  • 51

3 Answers3

99

There is a similar question here:

Control-r reverse-i-search in Bash: how do you "reset" the search in Cygwin?

Found another similar question on Super User:

(reverse-i-search) in Bash

Apparently, both mention Ctrl+s, which may do the trick.

starball
  • 20,030
  • 7
  • 43
  • 238
gdupont
  • 1,660
  • 18
  • 27
  • 1
    ctrl-s - standard emacs. – Mike Makuch Sep 26 '13 at 04:56
  • 55
    Important: To make `^-S` work, add `stty -ixon` to your bash profile (`~/.bashrc` on Linux, `~/.bash_profile` on OSX). Also note that reversing direction by pressing the respective other keyboard shortcut is initially a _no-op_ - all that changes is the display's prefix (`reverse-i-search` vs. `i-search`). Thus, to actually *take 1 step* in the other direction, press the keyboard shortcut *twice*. – mklement0 Jan 27 '14 at 22:51
  • 3
    What does no-op mean? What does `stty -ixon` do exactly? – zyxue Feb 29 '16 at 19:40
  • 1
    @zyxue noop means "no operation." It means that the shortcut is mapped to "do nothing." See [here](https://en.wikipedia.org/wiki/NOP). Without setting `-ixon`, ctrl-s tells the terminal to stop updating meaning you to have to push ctrl-q to resume normal operation. By setting `-ixon` you disable that behavior, which maps ctrl-s to `i-search`. – blockloop Jan 13 '17 at 02:45
  • 2
    @gdupont it looks like i-search is part of readline. The source is here: http://git.savannah.gnu.org/cgit/readline.git/tree/isearch.c?h=devel – Max Heiber Feb 17 '17 at 02:40
62

CTRL + S

...solved it for me AFTER using...

stty -ixon

If CTRL+S doesn't work for you is because according to Vincenzo Pii's accepted answer in another related thread:

The problem is that this binding, in many terminals, is used by default to send the pause transmission code (XOF).

As in man stty:

[-]ixon
    enable XON/XOFF flow control

So, if you have this option enabled on your terminal (the output of stty -a contains ixon withouth the - sign in front), you cannot use CTRL+S in the context of reverse-i-search.

To disable it, use the following command:

stty -ixon

And CTRL+S will give you a (i-search) (non reverse).

simhumileco
  • 31,877
  • 16
  • 137
  • 115
BringBackCommodore64
  • 4,910
  • 3
  • 27
  • 30
  • In my case `-ixon` is disabled but for some reason ^S symbols is still installed literally. I'm on `lxterminal`. – xji Apr 02 '18 at 12:56
7

Try delete, magically worked.

Others point to CTRL+s, but it doesn't work for me.

simhumileco
  • 31,877
  • 16
  • 137
  • 115
advisor21
  • 79
  • 1
  • 1