this post was submitted on 20 Mar 2025
8 points (90.0% liked)
Emacs
2429 readers
1 users here now
Our infinitely powerful editor.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
isearch
is probably one of the most widely known Emacs commands. Every Emacs user knows that they can run it usingC-s
(to search forward) andC-r
to search backwards. Everyone also knows they can keep pressingC-s
andC-r
to go over the list of matches in the current buffer. Even at this point that’s a very useful command. But that doesn’t even scratch the surface of what isearch can do!After you’ve started
isearch
you can actually do a lot more than pressingC-s
andC-r
:DEL
to cancel last input item from end of search string.RET
to exit, leaving point at location found.LFD
(C-j
) to match end of line.M-s M-<
to go to the first match,M-s M->
to go to the last match. (super handy)C-w
to yank next word or character in buffer onto the end of the search string, and search for it. (very handy)C-M-d
to delete character from end of search string.C-M-y
to yank char from buffer onto end of search string and search for it.C-M-z
to yank from point until the next instance of a specified character onto end of search string and search for it.M-s C-e
to yank rest of line onto end of search string and search for it.C-y
to yank the last string of killed text.M-y
to replace string just yanked into search prompt with string killed before it.C-q
to quote control character to search for it.C-x 8 RET
to add a character to search by Unicode name, with completion.C-g
while searching or when search has failed cancels input back to what has been found successfully.C-g
when search is successful aborts and moves point to starting point.You can also toggle some settings when
isearch
is active:M-s c
to toggle search case-sensitivity.M-s i
to toggle search in invisible text.M-s r
to toggle regular-expression mode.M-s w
to toggle word mode.M-s _
to toggle symbol mode.M-s '
to toggle character folding.M-s SPC
to toggle whitespace matching.In incremental searches, a space or spaces normally matches any whitespace defined by the variable
search-whitespace-regexp
; see also the variablesisearch-lax-whitespace
andisearch-regexp-lax-whitespace
.Type
M-s e
to edit the search string in the minibuffer. That one is super useful! Also supported is a search ring of the previous 16 search strings:M-n
to search for the next item in the search ring.M-p
to search for the previous item in the search ring.C-M-i
to complete the search string using the search ring.Last, but not least - you can directly search for the symbol/thing at point:
M-s .
to search for the symbol at point. (useful in the context of programming languages)M-s M-.
to search for the thing (e.g. word or symbol) at point.One of the most useful parts of that is the fact that a region is a thing. So you can mark a region (e.g. with
expand-region
ormark-*
) andM-s M-.
to immediately search for other instances of that text. Powerful stuff!Tip: You don’t really have to remember all those keybindings - just remember you can press
C-h b
to show them. (after you’ve startedisearch
) Most of the above text is coming straight from the docstring ofisearch
.It’s funny that I’ve been using Emacs for almost 20 years, I use
isearch
numerous times every day and I still often forget about much of its functionality. There’s more toisearch
, though. Did you know it’s widely customizable as well? If you check its options withM-x customize-group isearch
you’ll see there are over 30 (!!!) options there! Admittedly, I never used any of them, but you’ve got quite a lot of opportunities to tweak the behavior of isearch if you want to. Here’s an example of a customization some of you might find useful:I hope you learned something useful today! Keep searching (the Emacs docs)!`___`
seriously though