reddit / emacs

How to clear the current isearch term without exiting isearch?

Ghosty141 · 2022-10-25 18:26
This seems awfully simple but I can't find how to do this. I just want to bind S-C-<backspace> to completely clear isearch without exiting the "prompt" (yes I know it's just the echo area). Is there any way to do this?
eleven_cupfuls · 2022-10-25 19:02
It is not available already built in, but fortunately there _is_ a built-in command, `isearch-del-char`, that can be used to create it, [like so](https://gitlab.com/woolsweater/dotemacs.d/-/blob/db0d2d3ca351b6aa63a2ce1cf541661000dfe713/startup/builtin.el#L360-364): (defun isearch-delete-entire-query () "Like `isearch-del-char' but remove the _entire_ search string at once." (interactive) (isearch-del-char most-positive-fixnum)) Just bind that in `isearch-mode-map`: `(define-key isearch-mode-map (kbd "S-C-<backspace>") #'isearch-delete-entire-query)`
Ghosty141 · 2022-10-25 19:48
Oh you can just add an argument, nice! I thought about repeatedly calling del-char but that seemed *too wrong*. Thanks!
jplindstrom · 2022-10-25 21:16
If you type `C-s` to enter isearch, then you can type the usual `C-h m` to show the mode docs. That will show you various interesting keys, including ``` Type C-h b to display all Isearch key bindings. ``` So if you type `C-s` and then type `C-h b`, it'll show you other interesting keys, including ``` M-e isearch-edit-string ``` So you can use that and then clear the isearch string.