2

reverse-search-history is bound to C-r by default. One can type C-r to start the search, and then type C-r again to jump to an earlier match.

I have bound reverse-search-history to \er (Alt-r). This new binding works for the initial search, but subsequent presses of Alt-r don't continue searching. C-r seems to still be needed to repeat the backwards search.

Is there a way to make Alt-r work for the repeat function as well? Or a way to bind the 'continue searching' function to any key other than the default? I was able to do it in emacs, but couldn't find any relevant documentation for bash/readline.

1 Answer 1

1

After some tests I have this answer:

In linux virtual console, the "Alt-R" produces a "^[r" in showkey -a, that is "Esc" and "r", and the Escape stops the reverse search...by deleting the search string.

In xterm, it works; the \M-r appears as "ò":

]# bind -p |grep ' reverse-se'
"\C-r": reverse-search-history
"\e[172": reverse-search-history
"\e[1;3A": reverse-search-history
"ò": reverse-search-history

The "\e..." work only partly, as you describe (it is the modified UP arrow).


man bash does have some info:

   convert-meta (On)
          If set to On, readline will convert characters with the eighth bit set to an
          ASCII key sequence by stripping the eighth bit and prefixing an escape char-
          acter (in effect, using escape as the meta prefix).  The default is On,  but
          readline will set it to Off if the locale contains eight-bit characters.

Here the readline variable:

isearch-terminators
    ... If this variable has not been given a value,
    the characters ESC and C-J will terminate an incremental search.
2
  • Thanks so much for your reply. This looked promising but I have not been able to get my bash (on Ubuntu in either rxvt or console) to do anything differently with 'set convert-meta off'. I added this to both .inputrc and .bashrc and restarted the shell, but showkey -a still gives "^[r" for Alt-r. My locale is en_US.UTF-8, FWIW. Dec 20, 2019 at 2:01
  • 1
    BUT, your idea about the escape prefix causing the search string to be reset turned out to be spot on! I added 'set isearch-terminators "\C-j"' in order to remove ESC (C-[) from the default value, and now reverse-search-history works for me on Alt-r! Marking as answered. Dec 20, 2019 at 2:12

You must log in to answer this question.

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