0

I'd like to bind jump-to-register with C-', like this: (global-set-key (kbd "C-'") 'jump-to-register.

However, C-' is already bound to org-cycle-agenda-files.

I tried to unbind C-' with (global-unset-key (kbd "C-'")) but it didn't work.

What am I doing wrong?

4
  • global-set-key sets the global keymap which is overridden by every other keymap including org-mode-map. See this question (out of many) for a recent discussion. Jan 8, 2023 at 0:02
  • Is global-unset-key also overridden? How to unbind a key bound by org-mode-map then?
    – crocefisso
    Jan 8, 2023 at 0:34
  • Your question is, as you say in your comment, "How to unbind a key bound by org-mode-map ". That's no doubt a duplicate question.
    – Drew
    Jan 8, 2023 at 2:41
  • Yes it does, thank you very much. Here is the proper solution : (define-key org-mode-map (kbd "C-'") nil) and (global-set-key (kbd "C-'") 'jump-to-register)
    – crocefisso
    Jan 8, 2023 at 3:07

1 Answer 1

1

Solution:

(define-key (current-global-map) [remap org-cycle-agenda-files] 'jump-to-register)

Explanations:

Remapping Commands

You can tell Emacs that you want to replace all keys pointing to a certain command with one of your own choosing by using the remap notation.

You must do this instead of passing a key to the key bind function you are using. This is the best way of replacing existing commands with your own, as Emacs does the hard work of figuring out all the keys it needs to rebind.

Source: Mastering Emacs

EDIT:

Here is a preferable solution:

(define-key org-mode-map (kbd "C-'") nil)
(global-set-key (kbd "C-'") 'jump-to-register)

Not the answer you're looking for? Browse other questions tagged or ask your own question.