I've installed smex through MELPA as a replacement for the default M-x (execute-extended-command). The issue is that in smex, certain global keybindings don't work. For instance, C-h should work as backspace, yet in smex it's still bound to default help.

(global-set-key (kbd "C-h") 'delete-backward-char)

Any idea why the above global-set-key might not work in smex, while it does elsewhere (in minibuffer, eshell, etc.)?

Addendum to Jesse's answer

When using ido-vertical-mode one should also rebind M-p:

(defun ido-vertical-define-keys ()
(define-key ido-completion-map (kbd "C-n") 'ido-next-match)
(define-key ido-completion-map (kbd "C-p") 'ido-prev-match)
(define-key ido-completion-map (kbd "M-p") 'previous-history-element))
  • IMO C-h is way more valuable as a help binding (especially C-h v, C-h f and C-h k/C-h c) unless you prefer to use F1 instead. – Kaushal Modi May 22 '15 at 18:56
  • @kaushalmodi, but isn't backspace somewhat out of reach? Or do you use some other binding for delete-backward-char altogether? – Blaz May 22 '15 at 19:03
  • I've got used to DEL (backspace) and C-DEL; don't find it that inconvenient. Probably I use C-d and M-d equally or more. – Kaushal Modi May 22 '15 at 19:06
  • 1
    About the edit you made related to ido-vertical-mode.. note that you then are losing the C-p and C-n bindings which are more intuitive for up/down navigation in ido-vertical-mode. You should copy that whole function to your emacs config and then only edit the bindings you care about. – Kaushal Modi May 22 '15 at 19:14

I also had this problem and couldn't fix. My workaround was overriding the smex keybindings function:

(defun smex-prepare-ido-bindings ()
  (define-key ido-completion-map (kbd "TAB") #'minibuffer-complete)
  (define-key ido-completion-map (kbd "M-p") #'previous-history-element)
  (define-key ido-completion-map (kbd "M-.") #'smex-find-function)
  (define-key ido-completion-map (kbd "C-h") #'delete-backward-char)
  (define-key ido-completion-map (kbd "C-a") #'move-beginning-of-line))
  • Nice. There's only one snag: M-p doesn't get defined and is still bound to "ido-toggle-prefix, which is an interactive compiled Lisp function in `ido.el'." – Blaz May 22 '15 at 18:37
  • 1
    @courteous I bet you have ido-vertical installed too because that sets M-p binding to ido-toggle-prefix (as it needs to use the original binding of ido-toggle-prefix.. C-p for ido-prev-match (ido match navigation)). To change that, you will need to override the ido-vertical-define-keys function in the same fashion as this solution for overriding bindings set by smex. – Kaushal Modi May 22 '15 at 18:51
  • @kaushalmodi, ido-vertical it is. That fixed the M-p as well. Regarding your edit of Jesse's answer: what difference do hashtags # make? Also, how did you go about finding that it is ido-vertical-define-keys that must be overridden? – Blaz May 22 '15 at 19:00
  • 1
    @courteous My approach to find such bindings is probably unconventional but I simply did ag 'p.*ido-toggle-prefix' in my ~/.emacs.d and emacs source code lisp/ directories... and about the sharp-quotes. ag is like grep but faster. – Kaushal Modi May 22 '15 at 19:09

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.