3

Everyone knows you can repeat the last I-search with C-s C-s, but that doesn't preserve all the parameters from the last search. As a concrete example, I often use symbol I-search (M-s _), and typing M-s _ C-s is a fair bit cumbersome when going through a lot of matches.

It would be nice if C-s C-s could see if the last I-search was a symbol search and reactivate that. Similar things can of course be said for other I-search states, like regex searches (though that isn't quite as cumbersome to do manually to begin with).

Is there a way to do this with the existing I-search implementation, or will I have to write it myself?

2
  • 2
    What version of emacs? In current upstrean, toggling symbol search, quitting the search and restarting it with C-s C-s brings back both the symbol and the option for further searching.
    – NickD
    Commented Oct 12, 2022 at 3:36
  • @NickD: Would you look at that. I'm still using Emacs 26.1 on this computer, but on another computer with 27.1 you are indeed right that it does repeat the search as I wanted it to. That's great!
    – Dolda2000
    Commented Oct 12, 2022 at 12:11

2 Answers 2

2

Per the comments, starting from Emacs 27.1 this happens automatically.

The NEWS item is:

*** Isearch now remembers the regexp-based search mode for words/symbols and case-sensitivity together with search strings in the search ring.

E.g. running emacs -Q and acting in the standard scratch buffer:

;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.

Using M-s_ is and then repeatedly typing C-s will cycle through only the two instances of the word is, skipping Lisp and visit.

If you then exit the isearch with RET (and/or any other editing) and then use C-sC-s to repeat the previous search, it will again match only the two instances of the word is.

0

Use M-s . for symbol search, and M-p and M-n for retrieving previous search strings (or if it is the first search, suggested search strings).

M-s . runs the command isearch-forward-symbol-at-point (found in global-map), which is an interactive byte-compiled Lisp function in isearch.el.


When in minibuffer use M-p and M-n to retrieve previous search terms.

M-p runs the command isearch-ring-retreat (found in overriding-terminal-local-map), which is an interactive byte-compiled Lisp function in isearch.el.


M-n runs the command isearch-ring-advance (found in overriding-terminal-local-map), which is an interactive byte-compiled Lisp function in isearch.el.


You can use M-p and M-n almost always in the minibuffer to retrieve historical items. It works for simple search, as well as search and replace.

1
  • 1
    This doesn't seem to answer the question that was asked - about repeating the same type of search, rather than using the history of search values. Commented Oct 12, 2022 at 11:29

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.