This page is about Isearch+, that is, library isearch+.el and its companion library isearch-prop.el. These libraries extend standard Emacs library isearch.el
, which provides IncrementalSearch. (Neither of these extension libraries requires the other. They are complementary, but they enhance each other.)
These are the main isearch-prop.el features:
‘face’
text property with a value of ‘font-lock-comment-face’
or ‘font-lock-string-face’
. Search overlays or text properties. From within Isearch: ‘C-t’
(or ‘C-M-t’
for regexp search). First time, or with a prefix argument, you are prompted for the property and its values. See the doc string of command ‘isearchp-property-forward’
.‘face’
and other text properties for use with ‘C-t’
, you can use command ‘isearchp-put-prop-on-region’
(outside of Isearch) to add a text property to a zone of text. By default, it applies the last property and value whose zones you searched using ‘C-t’
, but a prefix argument lets you specify the property and value to apply. This gives you an interactive way to set up zones for text-property search (‘C-t’
). For property ‘face’
, empty input removes all faces from the region.‘M-s h f’
(to highlight) and ‘M-s u f’
(to unhighlight) while searching.‘isearchp-zones-forward’
and ‘isearchp-zones-forward-regexp’
. You can use different such zone sets. Library zones.el
gives you an easy, interactive way to define them. A prefix argument to the commands that search a set of zones prompts you for a variable whose value is such a set. By default the variable is ‘zz-izones’
.zones.el
then you can also make a set of zones or its complement (the set of anti-zones) invisible, so that you do not see it at all, including while searching. The commands for this are ‘isearchp-make-zones-invisible’
, ‘isearchp-make-anti-zones-invisible’
, ‘isearchp-toggle-zones-invisible’
, ‘isearchp-toggle-anti-zones-invisible’
, and ‘isearchp-toggle-zone/anti-zone-visibility’
.zones.el
then you can also, during Isearch, replace (‘M-s z s’
) or update (‘M-s z a’
) the current list of zones from the boundaries of lazy-highlighted text, or you can create a noncontiguous region from that text (‘M-s z r’
).C-M-~
’ (command ‘isearchp-toggle-complementing-domain’
).‘isearchp-dim-non-prop-zones-flag’
controls whether such dimming occurs. You can toggle it anytime during Isearch, using ‘C-M-D’
(aka ‘C-M-S-d’
). Option ‘isearchp-dimming-color’
defines the dimming behavior. It specifies a given background color to use always, or it specifies that the current background color is to be dimmed a given amount.‘isearchp-thing’
. This is equivalent to using command ‘isearchp-thing-define-contexts’
, which marks such zones with a text property, and then using ‘isearchp-property-forward’
.‘isearchp-next-visible-thing’
and ‘isearchp-previous-visible-thing’
. For best results I recommend that you also use library thingatpt+.el. It enhances the vanilla treatment of THINGS and fixes various vanilla thing-at-point bugs.‘isearchp-imenu’
, ‘isearchp-imenu-command’
, ‘isearchp-imenu-macro’
, and ‘isearchp-imenu-non-interactive-function’
. Since ImenuMode is based on regexps that recognize definitions, these commands are based on the behavior of ‘isearchp-regexp-context-search’
.‘isearchp-remove-property’
and ‘isearchp-remove-all-properties’
. By default, the latter removes only properties whose names begin with ‘isearchp-’
. These are the properties inserted automatically by the commands of library isearch-prop.el, when you do not specify a property.M-;
’ (command ‘isearchp-toggle-hiding-comments’
). You can toggle ignoring comments during Isearch, using `C-M-;
’ (command ‘isearchp-toggle-ignoring-comments’
).These are the main isearch+.el features:
‘ISEARCH’
for case-insensitive; ‘Isearch’
for case-sensitive.‘isearchp-highlight-regexp-group-levels-flag’
. For lazy-highlighting of other search hits, the odd groups are highlighted differently from the even groups. The same highlighting is available for ‘query-replace-regexp’
(`C-M-%
), if you also use library replace+.el – see ReplacePlus.‘isearchp-restrict-to-region-flag’
. Deactivation of the active region is controlled by option ‘isearchp-deactivate-region-flag’
. Both of these are available for Emacs 24.3 and later.‘C-x n’
(command ‘isearchp-toggle-region-restriction’
) and ‘C-SPC C-SPC’
(command ‘isearchp-toggle-region-deactivation’
) during search to toggle ‘isearchp-restrict-to-region-flag’
and ‘isearchp-deactivate-region-flag’
, respectively, but in each case the new value takes effect only when the current search is exited.‘M-x rectangle-mark-mode’
).M-%
’ from Isearch, to use ‘query-replace’
). The main job of that library is to show information about the active region in the mode line. And whenever you invoke a replacement command or Isearch for the active region, that region information is highlighted specially. See ModeLineRegion for more info.‘isearchp-set-region-flag’
– Non-‘nil’
means automatically set the region around the last search target.‘isearchp-toggle-set-region’
, bound to ‘M-s M-SPC’
during isearch – toggle ‘isearchp-set-region-flag’
.‘set-region-around-search-target’
– manually set the region around the last search target.‘C-M-RET’
(command ‘isearchp-act-on-demand’
– Emacs 22+ only) to invoke the action function that is the value of option ‘isearchp-on-demand-action-function’
. That function is passed the current search-hit string and its start and end positions in the buffer. Search moves to the next hit in the same search direction, so just repeating ‘C-M-RET’
carries out the action on subsequent hits.‘isearchp-on-demand-action-function’
is function ‘isearchp-replace-on-demand’
, which replaces the search hit. This means that you can replace (or delete) chosen search hits on demand. By default, the replacement string is empty, so with no prefix argument the action is to delete the search hit (replace it with nothing).‘isearchp-replace-on-demand’
(‘C-M-RET’
) prompts for the replacement, which is used thereafter until you again use a prefix arg. Since you can use a prefix arg at any time, you can provide different replacements for different search hits. When prompted, if you clear the minibuffer and hit ‘RET’
, hit replacement just becomes search-hit deletion. [NOTE: To use a prefix arg within Isearch, you must set ‘isearch-allow-prefix’
(if available) or ‘isearch-allow-scroll’
to non-‘nil’
.]‘C-u’
) or a numeric prefix arg of value 1 (e.g. ‘C-1’
), ‘isearchp-replace-on-demand’
replaces only the current search hit.‘M--’
or ‘C--’
), ‘isearchp-replace-on-demand’
toggles automatic replacement by just searching. Automatic replacement means that each time you use a search key (e.g. ‘C-s’
) to visit a search hit, the hit is automatically replaced, without your needing to hit ‘C-M-RET’
. Using a prefix arg again with ‘C-M-RET’
cancels this (as does quitting and restarting Isearch).‘C-8’
or ‘C-u 200’
), ‘isearchp-replace-on-demand’
replaces N search hits (but it stops at the search limit, if reached).‘C-0’
), ‘isearchp-replace-on-demand’
replaces all remaining search hits (up to the search limit).‘C-M-RET’
) the replacement text can be either inserted literally, as is, or interpreted as in ‘query-replace-regexp’
. In the latter case, you can use `\&
’, `\=\N
’, `\
#’, `\,
’ and `\?
’.`\(e\)\|a'
and a replacement pattern of `\,(if \1 "a" "e")'
. Each ‘C-M-RET’
will then swap ‘e’
for ‘a’
and vice versa.‘query-replace-regexp’
and node ‘Regexp Replace’
of the Emacs manual for more information.\?
’ is supported, but it is not very useful in this context, because it prompts you to edit the result each time you hit ‘C-M-RET’
. Instead, use ‘C-u C-M-RET’
whenever you want to change (edit) the replacement pattern.)C-M-`
’ (‘isearchp-toggle-literal-replacement’
) anytime during Isearch to toggle whether replacement text is used literally or interpreted per the special regexp-replacement constructs.\&
’ and so on is to use `C-M-`
’.‘isearchp-noprompt-action-function’
is a function that is invoked automatically, after you visit each search hit. The function is called with no arguments. It cannot use the minibuffer, but it can modify buffer contents. The variable is reset to ‘nil’
when you quit Isearch. As an example of use, command ‘isearchp-replace-on-demand’
with a negative prefix arg sets this to ‘isearchp-replace-match’
, which causes automatic replacement each time you visit a search hit.‘isearchp-nomodify-action-hook’
(Emacs 22+ only) is also run after each search visit. Its functions also must accept the same arguments as ‘isearchp-act-on-demand’
. The functions can use the minibuffer, but they must not update the buffer text (in a way noticeable by Isearch), or else that will likely lead to a call-stack overflow. This is because they are called with Isearch suspended during ‘isearch-update’
(which can itself be invoked by the action…).‘isearchp-regexp-quote-yank-flag’
) and command (‘isearchp-toggle-regexp-quote-yank’
, bound to `C-`
’) to toggle quoting (escaping) of regexp special characters. With escaping turned off, you can yank text such as ^\*.*
without it being transformed to \^\\\*\.\*
.M-:
’ (‘isearchp-eval-sexp-and-insert’
) prompts you for a Lisp sexp, evaluates it, and appends the value to the search string. This is useful, for example, to use ‘rx’
or another regexp-creation helper to create a regexp search pattern. For example: `C-M-s M-: (rx (and line-start (1+ (in "("))))
’ searches using the result of that ‘rx’
sexp, which is "^(+"
. (The double-quote chars are removed.) Remember too that you can use `C-u M-:
’ after ‘M-e’
. That inserts the sexp value into the minibuffer, where you are editing the search string. Use this when you do not want to simply append the sexp value to the search string, but instead you want to do some editing of it or the rest of the search string.‘M-g’
(‘isearchp-retrieve-last-quit-search’
) yanks the last successful search string (regexp or plain) from when you last hit ‘C-g’
in Isearch. Sometimes you search for something but abandon the search — you just want to check the locations of something, without staying at any of them. Afterward, if you want to find them again, use ‘M-g’
. This yanks that search string, so you can append it to whatever you are already searching for.‘C-x r g’
(‘isearchp-append-register’
) appends the contents of a register to the search string. You are prompted for the register to use. This is the same key that is bound globally to ‘insert-register’
. If you want this key to instead exit Isearch and insert the register in the buffer, then define this key in ‘isearch-mode-map’
as `nil` (i.e., unbind it), and optionally bind ‘isearchp-append-register’
to a different key in ‘isearch-mode-map’
.‘C-M-y’
(‘isearch-yank-secondary’
) yanks the secondary selection onto the search string, if you also use library second-sel.el (see secondary selection enhancements).‘C-c’
(‘isearchp-yank-char’
) yanks successive characters onto the search string.C-_
’ (‘isearchp-yank-symbol-or-char’
) yanks successive symbols (or words or subwords or chars) onto the search string.C-(
’ (‘isearchp-yank-sexp-symbol-or-char’
) yanks successive sexps (or symbols or words or subwords or chars) onto the search string.‘M-w’
(‘isearchp-kill-ring-save’
) copies the current search string to the kill ring. You can then, for example, use ‘C-s M-y’
to search for the same thing in another Emacs session. (I use this all the time, but you might not use multiple Emacs sessions.) Note that if you did not have this feature then you would need to select the search-string text (in the text buffer or in the ‘M-e’
Isearch edit buffer) and copy it to the kill ring. (Note: ‘M-w’
used to toggle word search, but ‘isearch-toggle-word’
is now ‘M-s w’
.)‘C-y’
(in addition to any other Isearch bindings):C-y C-_ isearchp-yank-symbol-or-char C-y C-( isearchp-yank-sexp-symbol-or-char C-y C-2 isearch-yank-secondary C-y C-c isearchp-yank-char C-y C-e isearchp-yank-line C-y C-w isearchp-yank-word-or-char C-y C-y isearch-yank-kill C-y M-y isearch-yank-pop
‘isearch-yank-secondary’
, ‘isearch-yank-kill’
, and ‘isearch-yank-pop’
) by just repeating the last key. For example: ‘C-y C-e C-e C-e’
adds the text up to the end of three lines.‘C-x 8 RET’
(‘isearch-char-by-name’
) reads the name of a Unicode character with completion and appends it to the search string. Same thing when editing the search string (i.e., after ‘M-e’
). This is part of GnuEmacs starting with Emacs 24.4.‘C-x o’
(‘isearchp-open-recursive-edit’
) opens a recursive editing session, where you can do anything you like (including search for something different). Using ‘C-M-c’
closes the recursive editing session and resumes the search (from the current position when you hit ‘C-M-c’
).‘isearchp-resume-with-last-when-empty-flag’
non-‘nil’
(the default) means that if Isearch is resumed with an empty search string, after being suspended, the previous search string is used. If ‘nil’
, it is resumed with an empty search string, as if starting over from the resumed location.‘C-g’
after successfully finding matches restores not only the original position but also its relative position in the window. IOW, you get back to what you saw before searching. Fixes GnuEmacs bug #12253 for Isearch.‘C-g’
, or removed/replaced manually if you use ‘C-M-l’
(see next) or automatically if you use ‘M-k’
(see below). I added this feature to GnuEmacs 23.1.‘C-M-l’
(‘isearchp-remove-failed-part’
) removes the failed part of the search string, if any. ‘C-g’
does this as well, but ‘C-g’
also has an effect when search is successful.C-<backspace>
’ (‘isearchp-remove-failed-part-or-last-char’
) also removes the failed part, if any. If there is none then it removes the last character. You might prefer to bind this to ‘DEL’
(Backspace), in place of ‘isearch-delete-char’
.‘M-k’
(‘isearchp-cycle-mismatch-removal’
) cycles automatic removal or replacement of the input portion that does not match. The behavior is controlled by the value of option ‘isearchp-drop-mismatch’
:‘replace-last’
– Your current input replaces the last mismatched text. You can always see your last input, even if it is a mismatch. And it is available for editing using ‘M-e’
.‘nil’
– Your current input is appended, even if the previous input has a mismatched portion.‘isearchp-drop-mismatch-regexp-flag’
controls whether regexp search respects option ‘isearchp-drop-mismatch’
. If ‘nil’
(the default value) then regexp search acts as if ‘isearchp-drop-mismatch’
were ‘nil’
. This is because typing a regexp such as `[a-w]
’ can be problematic when mismatches are automatically replaced. There is no problem for many regexp patterns however, so you might prefer customizing this to non-‘nil’
and using ‘M-k’
to turn ‘isearchp-drop-mismatch’
off only temporarily, when needed.‘isearchp-repeat-search-if-fail-flag’
means that Isearch fails only when there are no search hits within the search limits. If there are search hits, and if there are no more hits in the current search direction, then search restarts automatically at the limit. You can toggle this behavior using ‘M-s M-k’
anytime during Isearch.‘isearchp-ring-bell-function’
to suppress or replace bell ringing (‘ding’
) during Isearch (but not for quitting with ‘C-g’
). Set it to ‘ignore’
, for example, to suppress any indication of an error. Set it to a function such as ‘echo-bell’
(from library echo-bell.el), to indicate errors only visually.‘nil’
option ‘isearchp-toggle-option-flag’
, which you can toggle using ‘M-s v’
(‘isearchp-toggle-option-toggle’
), determines whether commands that toggle behavior also toggle an associated user option. For such commands, a prefix argument flips the behavior, as if ‘isearchp-toggle-option-flag’
were toggled temporarily. Currently this feature applies to toggles ‘M-c’
(case-sensitivity) and ‘M-s i’
(matching hidden text).‘M-c’
(‘isearch-toggle-case-fold’
) toggles case sensitivity. If option ‘isearchp-toggle-option-flag’
is non-‘nil’
then it toggles option ‘isearchp-case-fold’
to change the sensitivity from now on. Otherwise, the option value is not changed, so the effect is for the current search only.‘M-s i’
(‘isearch-toggle-invisible’
) toggles invisible-text sensitivity. If option ‘isearchp-toggle-option-flag’
is non-‘nil’
then it toggles option ‘search-invisible’
to change the sensitivity from now on. Otherwise, the option value is not changed, so the effect is for the current search only.C-+
’ (‘isearchp-toggle-search-invisible’
) toggles the value of option ‘search-invisible’
. The effect is like that of ‘M-s i’
with no prefix argument and with non-‘nil’
‘isearchp-toggle-option-flag’
.‘M-s h L’
(‘isearchp-toggle-lazy-highlighting’
) toggles the value of option ‘isearch-lazy-highlight’
. Turning this highlighting off can sometimes speed up searching considerably, in particular for symmetric character folding.‘M-s h l’
(‘isearchp-toggle-lazy-highlight-cleanup’
) toggles the value of option ‘lazy-highlight-cleanup’
. When the option value is ‘nil’
you can continue to see the search hits highlighted from the last search. Toggle the option off, or use command ‘isearch-lazy-highlight-cleanup’
, to remove the highlighting. When ‘M-s h l’
turns cleanup on it also sets option ‘lazy-highlight-buffer’
to ‘nil’
, turning off full-buffer highlighting.‘M-s h b’
(‘isearchp-toggle-lazy-highlight-full-buffer’
) toggles the value of option ‘lazy-highlight-buffer’
. When the value is ‘t’
Isearch lazy-highlights the entire buffer. The default value of ‘nil’
means it lazy-highlights only the buffer parts currently shown (but previously highlighted parts remain highlighted). ‘M-s h b’
also toggles option ‘lazy-highlight-cleanup’
, in the other direction. This is because in most cases where you want to lazy-highlight the whole buffer you also want to keep that highlighting. You need Emacs 24.3+ to take advantage of ‘lazy-highlight-buffer’
.M-s
#’ (‘isearchp-toggle-showing-match-number’
) toggles showing the current match number and total matches in the Isearch prompt (option ‘isearch-lazy-count’
).M-s %
’ (‘isearchp-toggle-limit-match-numbers-to-region’
) toggles whether match number are limited to the active region when option ‘isearchp-restrict-to-region-flag’
is non-‘nil’
. (Emacs 24.3+)M-=
’, by default. They are on prefix keymap ‘isearchp-toggles-map’
which you can bind to any key in ‘isearch-mode-map’
. If you forget a `M-=
’ toggle key, you can use `M-= C-h
’ while searching to show them all.‘next’
, ‘prior’
repeat the last Isearch forward and backward (easier than using the chords ‘C-s’
, ‘C-r’
).‘C-end’
– go to the longest line. Repeat to go to the longest line following that one in the buffer. As usual, ‘C-g’
puts you back where you started. This binding is made only if you also use library misc-cmds.el. See Find Long Lines.‘C-h’
provides help on Isearch while searching. Library isearch+.el also redefines ‘isearch-mode-help’
so that it lists all Isearch bindings and ends Isearch properly.‘M-e’
(‘isearch-edit-string’
) automatically puts the cursor at the first mismatch position in the search string, for easy editing. Whereas ‘C-g’
(see also ‘M-k’
) removes all of the mismatch, this feature lets you change or insert a character or two, without losing the rest of the search string.‘isearchp-initiate-edit-commands’
, that specifies commands whose keys will not exit Isearch but will instead initiate editing of the search string. For example, if ‘backward-char’
is included in the list then ‘C-b’
and ‘left’
will just move the cursor backward over the search string so you can change, delete, or insert chars in the middle somewhere. This makes the search string more minibuffer-like.‘C-s’
etc. to search for it. This is controlled by user option ‘isearchp-mouse-2-flag’
.M-s =
’ (command ‘isearchp-toggle-symmetric-char-fold’
) to toggle whether character folding is symmetric. This feature is not available now, since vanilla Emacs changed the way vanilla file character-fold.el
works.See Also:
‘query-replace’
. In particular, the ability to select (put the region around) the last replacement.