I use C-h as an alias for delete-backward-char everywhere.

But when I do isearch it exits the search instead of deleting the character before the cursor.

I tried binding C-h in isearch maps, but that didn't work:

(define-key minibuffer-local-isearch-map (kbd "C-h") 'delete-backward-char)
(define-key isearch-mode-map (kbd "C-h") 'delete-backward-char)

Character gets deleted, but it is deleted in the buffer, not in the isearch prompt.

Is there a way to rebind C-h so it works in isearch prompt?

  • Isearch does not use the minibuffer, in spite of appearance (with the exception of M-e). – Drew May 30 '20 at 17:46

First, in general, Isearch uses the minibuffer only for M-e. So your minibuffer-local-isearch-map key binding is useless here. That's the keymap used when editing after M-e.

Second, your isearch-mode-map binding means that C-h ends up deleting the char in the buffer you're searching, not deleting a char from the search string. The current buffer remains the buffer you're searching.

This is what you need to do. It defines a command that pops the last char off of the end of the search string.

(defun foo ()
  "Delete last char of the search string."
  (unless (equal isearch-string "") (isearch-pop-state))

(define-key isearch-mode-map (kbd "C-h") 'foo)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.