I followed this answer and created my minor mode to avoid my keybindings being overridden by any major modes.

So I put this in my init.el:

(define-key my-keys-mode-map (kbd "C-h") 'delete-backward-char)
(define-key my-keys-mode-map (kbd "M-h") 'backward-kill-word)

It is working with everything except when I am in helm-find-files. While M-h works, C-h doesn't. If I press it twice, Help buffer shows up saying:

Major Mode Bindings Starting With C-h:
key             binding
---             -------

C-h C-b     helm-send-bug-report-from-helm

Global Bindings Starting With C-h:
key             binding
---             -------

How can I disable C-h in helm-find-files and keep using my own keybinding?


C-h is special: see my answer to html-mode and custom backspace keybinding.

In short: whenever you rebind C-h you should also change the value of help-char.

To disable its action, do

(setq help-char nil)

(You can also set it to a different character.)

In addition to this, helm-find-files uses C-h as a prefix key. The code below replaces the C-h prefix with M-m, which should free C-h up to be used as "backspace":

(eval-after-load "helm-files"
  '(let ((helm-find-files-C-h-map (lookup-key helm-find-files-map (kbd "C-h"))))
     ;; make sure C-h is no longer a prefix key
     (define-key helm-find-files-map (kbd "C-h") nil)
     ;; rebind "C-h ..." to "M-m ..." to preserve functionality
     (define-key helm-find-files-map (kbd "M-m") helm-find-files-C-h-map)))
  • It doesn't work. Now C-h does nothing and C-h C-h shows C-h C-h is undefined Dec 17 '14 at 16:54
  • @Boccaperta-IT: I updated the answer; please give it another try. Dec 17 '14 at 17:20
  • Adding the code prompts an error upon startup: Debugger entered--Lisp error: (void-function keymap) (keymap (keymap (2 . helm-send-bug-report-from-helm)) keymap (109 . helm-help) (104 . undefined) (8 . undefined) (4 . helm-debug-output)) (lambda nil (keymap (keymap (2 . helm-send-bug-report-from-helm)) keymap (109 . helm-help) (104 . undefined) (8 . undefined) (4 . helm-debug-output)))() Dec 17 '14 at 17:28
  • Using (define-key helm-find-files-map (kbd "C-h") nil) works. There is no need to use (setq help-char nil). Thanks for pointing me in the right direction. Dec 17 '14 at 17:36
  • @Boccaperta-IT: I think I fixed the code in the answer (needed to quote the let-form). As for setting help-char, you don't need it to make helm work, but you may need it for other Emacs features (such as skeletons) to work (see the question I linked to). Dec 17 '14 at 17:46

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.