Weekly Emacs tip #21 — Emacs Redux writes: You have no idea how powerful isearch is!
A few weeks ago, Bozhidar Batsov, writer of the Emacs Redux blog wrote a post on isearch, the function you use to search text in the current buffer, and how there is a lot more to it than just typing C-s to search for some text.
I use C-s (isearch-forward) and C-r (isearch-backward) a lot. If fact, I think I do most of my “regular” text searches with them. The basic idea is: hit C-s or its counterpart, start typing your search string and Emacs will jump to the next (or previous) occurrence of that string. A subsequent press of C-s will bring you to the next occurrence, and so forth. Remember that switching the search direction while searching (keeping the same search string) is fine: just alternate between C-s and C-r.
Most of the time, after I found the occurrence I was looking for, I hit Enter to end the search and that’s it. What I also knew is that you can use C-y to yank (paste) killed text as the search string and a subsequent M-y to cycle through previous kills. Similarly, you can use M-p (a mnemonic for “previous”) and M-n (for “next”) to go back and forth in the list of previously used search terms1.
However, as Batsov explains, there are a whole bunch of extra commands you can call while searching with isearch. I won’t reiterate them here, except for
M-s rto toggle regular expression mode. This is a useful one as I usually would abort theisearch(withC-g) and restartisearch-forward-regexp(C-M-s) or itsbackwardcousin when I decide I needed to do a regexp search.M-s M-ito search for the thing (word) at point.
So go and read Batsov’s post, even if you won’t remember all of it! Just write a few shortcuts down and practice those.
Footnotes:
Remember these
two keycombos, the are quite a few occasions in Emacs where they have
the same behaviour. In fact, in my Zsh shell M-p and M-n can be used
to cycle through the command history; no more need to move my hand to
the up and down arrow keys :-).
1 Comment
Domenic
4 June 2025 at 02:36 •Nice share!