20.1.2 Repeating Incremental Search
Sometimes you search for ‘FOO’ and find one, but not the one you
expected to find. There was a second ‘FOO’ that you forgot
about, before the one you were aiming for. In this event, type
another C-s to move to the next occurrence of the search string.
You can repeat this any number of times. If you overshoot, you can
cancel some C-s characters with <DEL>.
After you exit a search, you can search for the same string again by
typing just C-s C-s: the first C-s is the key that invokes
incremental search, and the second C-s means “search again.”
If a search is failing and you ask to repeat it by typing another
C-s, it starts again from the beginning of the buffer.
Repeating a failing reverse search with C-r starts again from
the end. This is called wrapping around, and ‘Wrapped’
appears in the search prompt once this has happened. If you keep on
going past the original starting point of the search, it changes to
‘Overwrapped’, which means that you are revisiting matches that
you have already seen.
To reuse earlier search strings, use the search ring. The
commands M-p and M-n move through the ring to pick a search
string to reuse. These commands leave the selected search ring element
in the minibuffer, where you can edit it. To edit the current search
string in the minibuffer without replacing it with items from the
search ring, type M-e. Type C-s or C-r
to terminate editing the string and search for it.
You can change to searching backwards with C-r. If a search fails
because the place you started was too late in the file, you should do this.
Repeated C-r keeps looking for more occurrences backwards. A
C-s starts going forwards again. C-r in a search can be canceled
with <DEL>.
If you know initially that you want to search backwards, you can use
C-r instead of C-s to start the search, because C-r as
a key runs a command (isearch-backward
) to search backward. A
backward search finds matches that are entirely before the starting
point, just as a forward search finds matches that begin after it.