Skip to main content
Typo fixes
Source Link
NickD
  • 33.6k
  • 3
  • 30
  • 47

First, in general, Isearch uses the minibuffer only for M-e. So your minbufferminibuffer-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."
  (interactive)
  (unless (equal isearch-string "") (isearch-pop-state))
  (isearch-update))

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

First, in general, Isearch uses the minibuffer only M-e. So your minbuffer-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."
  (interactive)
  (unless (equal isearch-string "") (isearch-pop-state))
  (isearch-update))

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

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."
  (interactive)
  (unless (equal isearch-string "") (isearch-pop-state))
  (isearch-update))

(define-key isearch-mode-map (kbd "C-h") 'foo)
Source Link
Drew
  • 79.1k
  • 10
  • 123
  • 257

First, in general, Isearch uses the minibuffer only M-e. So your minbuffer-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."
  (interactive)
  (unless (equal isearch-string "") (isearch-pop-state))
  (isearch-update))

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