1

I was trying to bind (C-M-x) to er/expand-region but I checked the key combination with (C-h k) and noticed that it was binded to eval-defun. So I tried to unbind it with any of the following commands:

(global-set-key (kbd "C-M-x") nil)
(global-unset-key (kbd "C-M-x"))

But even using any of those won't unbind the key and (C-M-x) still will be running eval-defun

This is the result after running both commands:

Won't unbind the key

2
  • 2
    note that you don't need to unset a keybinding before applying a new binding. As long as you set your new keybinding in the appropriate keymap, you can leave any other bindings as they are
    – Tyler
    Aug 8 '21 at 17:56
  • 1
    I think this question is a duplicate, but I don't have the time now to search for it.
    – Drew
    Aug 8 '21 at 18:35
8

eval-defun is bound to C-M-x in lisp-interaction-mode-map while global-set-key and friends operate on global-map which has lower priority than any local key-map.

One way to bind C-M-x unconditionally is to use the bind-key package which provides bind-key* for this purpose:

(bind-key* "C-M-x" 'er/expand-region)
1
  • Looking at the customoze menu I was surprised that (it seems so) I cannot change the key bindings there.
    – U. Windl
    Aug 9 '21 at 7:05

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.