0

I want to bind ESC to quit from multiple-cursor mode.

This code doesn't work:

(define-key mc/keymap (kbd "<ESC>") 'mc/keyboard-quit)

How can I do it?

0

In order to use define-key you should try using the snippet below:

(with-eval-after-load 'multiple-cursors-core
  (define-key mc/keymap (kbd "<ESC>") 'mc/keyboard-quit))

so that the mc/keymap is defined by the file multiple-cursors-core.el/elc before a new keyboard shortcut is added thereto.

If the solution above does not work you can assign temporarily a custom keybind except ESC in order not to break other commands with the snippet below

(global-set-key (kbd "some keybind") 'mc/keyboard-quit)
  • 1
    Please explain this one-liner, saying how it answers the questino. – Drew Jun 15 at 14:47
  • define-key is a function that sets a keybind for a specifc mode. global-set-key is a wrapper of define-key that sets this keybind for every mode. If @Pfedj insists on using define-key he may need wrapping it like this (with-eval-after-load 'multiple-cursors (define-key mc/keymap ...) – George Xanthakis Jun 15 at 16:19
  • Your comment is the correct answer; i.e., (with-eval-after-load 'multiple-cursors (define-key mc/keymap ...)). The global-set-key should not be used here. The mc/keymap needs to be defined before it can be modified by adding additional keys or changing an existing. – lawlist Jun 15 at 16:29
  • Not sure this is a good idea, ESC is a prefix key equivalent to M-, so this will break all M- bindings. – npostavs Jun 15 at 16:35
  • Well at least he can use temporarily the global-set-key option if the solution (with-eval-after-load 'multiple-cursors (define-key mc/keymap ...)) does not work. – George Xanthakis Jun 15 at 17:21
0

I have solved the problem by changing <ESC> to <escape>:

(define-key mc/keymap (kbd "<escape>") 'mc/keyboard-quit))

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.