4

In the minibuffer, M-p (previous-history-element) is useful, but I find C-r (isearch-backward) to be even better, as it lets me recall a specific history element without going through them one by one.

When using isearch outside of the minibuffer (in the main text area), I can hit M-p at the isearch prompt to run isearch-ring-retreat, which pulls up the previous search string at the prompt. But I might be looking for a prior search string farther back, do it would be nice if I could use isearch to search the search-ring itself.

Is this possible?

2
  • While not exactly what you are looking for, most minibuffer aspects of Emacs offer tab completion (usually with an optional pop-up buffer of choices with an extra tab key) and typing a portion of the word to narrow down the choices and various methods to accept the choice with the enter key, or the mouse, ..... There is a brief entry in the manual discussing M-TAB for isearch-complete .... gnu.org/software/emacs/manual/html_node/emacs/… I played a few seconds with it and it didn't seem very user friendly, but perhaps you will have more patience than me.
    – lawlist
    May 16, 2017 at 8:01
  • See also related isearch-complete-edit ... with the same keyboard shortcut -- the former in the previous comment is when not editing the search string in the minibuffer, and the latter function is when editing the minibuffer. I spent another couple of minutes and see that the completion is only useful if the search history has been populated with a similar or same searches.
    – lawlist
    May 16, 2017 at 8:19

1 Answer 1

4
  1. When you use the minibuffer, C-r is not bound to isearch-backward. You are not using Isearch at that time, and Isearch does not use the minibuffer, even though it might look like it does.

    Perhaps you really mean M-r in the minibuffer, which is previous-matching-history-element and which completes against the current minibuffer input history.

  2. In Isearch you can use M-TAB (or C-M-i or ESC TAB - useful if your window manager captures M-TAB) to match a past search string using completion.

    (In Isearch M-r is bound to isearch-toggle-regexp. You can of course change which keys are bound to which Isearch commands, by using define-key with isearch-mode-map.)

  3. If you use library Isearch+ or Icicles then M-TAB provides better completion against the Isearch search-string histories (search-ring and regexp-search-ring).

6
  • I think you're mistaken about C-r not being bound to isearch-backward in the minibuffer. It's mentioned in the manual, and from the minibuffer, describe-key says C-r runs the command isearch-backward (found in global-map), even if I'm running emacs -Q. On the plus side, the C-M-i binding for isearch-complete is good to know, thanks for pointing it out.
    – ivan
    May 16, 2017 at 22:21
  • Are you talking about using Isearch in the minibuffer, e.g., to search your input text there? If so, yes, it is as you say. I thought you were talking about Isearch in general, and were thinking that it uses the minibuffer for the search string etc. Sorry for the confusion. When you use Isearch in the minibuffer the Isearch keymap is used, not the current minibuffer keymap, so there is no difference from using Isearch outside the minibuffer.
    – Drew
    May 16, 2017 at 22:24
  • However, I think you must be confused, because this: "but I find C-r (isearch-backward) to be even better" makes no sense. That just searches backward - it does not search through any history. And that's true whether you use it in the minibuffer or elsewhere. I'm guessing you're confusing C-r with M-r (in the minibuffer). The latter searches the current minibuffer history - not a search ring (history).
    – Drew
    May 16, 2017 at 22:29
  • Your question seems to be about searching the Isearch histories (search rings). That's the question I answered (#2 and #3, above).
    – Drew
    May 16, 2017 at 22:30
  • Sorry for the confusion. The first use-case I was describing, where I find C-r to be "even better", is when prompted for input (e.g. M-x, M-:, etc). In that context, C-r allows me to search through history elements (at least in 25.2.1 it does). I really wouldn't lie about this :) The second use-case is outside of the minibuffer, when using isearch in the main text area. When doing so, it would be neat to be able to use isearch within the isearch prompt itself in order to recall an earlier search string. I hope that clarifies.
    – ivan
    May 17, 2017 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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