Advanced isearch tips, settings, options and uses
Caveat
A technical video for advanced users of Emacs
Settings
; (setq isearch-lazy-highlight nil) ; remove lazy-highlight from incremental search (setq isearch-repeat-on-direction-change t) ; Remove "pause" when changing directions (setq isearch-wrap-pause nil) ; Never wrap isearch, either go up or down (setq search-ring-max 4) ; max length of search ring; default is 16; cycle using M-p and M-n (setq isearch-forward-thing-at-point '(region url email symbol sexp)) (setq isearch-allow-prefix t) ; do not allow scrolling commands to exit search, does not work in org-mode
Cancel search
ESC ESC ESC
or,
C-g C-g
Reuse earlier searches (see search-ring-max above)
M-p or M-n
Editing current search
C-g removes characters from search string not found in buffer. (Note: A second C-g at that point cancels the search entirely.)
C-M-d removes once character at a time from the search string (NEW)
DEL (Backspace) deletes the last typed character from the search string
M-e allows edits in minibuffer (more wide scale editing)
Search at point (all commands presuppose you are in isearch)
C-s C-w search word or sometimes character at point (Note: Emacs decides for you if it will search a word or character (heuristic search))
One can also use numeric arguments or re-invoke C-w to add more words/characters
C-s C-M-y search one character at time C-M-d removes one character at time
The heavy stuff
C-s C-M-w as above but searches for a symbol instead of word
C-s M-s C-e appends line
C-s C-M-z search from point to character x
C-s C-y search current copy/killed item
Some relief: New in Emacs 28: Search for "things"
M-s M-. (isearch-forward-thing-at-point)
Searches for things at point include the following: symbol, list, sexp, defun, number, filename, url, email, uuid, word, sentence, whitespace, line, and page.
Also useful for searching a region
An example config:
(setq isearch-forward-thing-at-point '(region url email symbol sexp))
Special Input for Incremental Search
M-s SPC toggle lax space searching
hello world
hello world
M-s c or M-c toggle case searching
M-s r or M-r toggle regexp and non-regexp search
M-s _ toggle symbol mode
C-j searches for a newline character; a nice way to see new lines quickly
M-s h r highlight search
M-s h l unhighlight search
C-h C-h help (works only if isearch is active)
M-s M-> goes to last occurrence
M-s M-< goes to first occurrence