4

I would like to override the C-c C-j keybinding. I put this in my init file

 (global-set-key (kbd "C-c C-j") 'counsel-org-goto)

However, it won't override the command org-goto (found in org-mode-map).

Thanks for your input!

Adelita
  • 155
  • 7
  • https://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs – phils Jul 13 '21 at 07:23
  • 3
    Does this answer your question? [How to override major mode bindings](https://emacs.stackexchange.com/questions/352/how-to-override-major-mode-bindings) – phils Jul 13 '21 at 07:49

1 Answers1

5

Try this expression:

(with-eval-after-load "org"
  (define-key org-mode-map (kbd "C-c C-j") #'counsel-org-goto))

The Org mode keymap "shadows" the global map. In Emacs, the keymaps of major modes take precedence over keybindings in the global keymap.

See this excellent tutorial from Mickey Petersen for a thorough discussion of the "keymap lookup order": https://www.masteringemacs.org/article/mastering-key-bindings-emacs.

phils
  • 48,657
  • 3
  • 76
  • 115
Tom Davey
  • 88
  • 5