I've seen many different ways of specifying key combinations for setting or unsetting key bindings in emacs. Some are quoted, others are bracketed, some are escaped, others are not. Do they all work in all contexts? Is there a best practice?
Some examples from my init file which may or may not work:
(define-key org-mode-map (kbd "<M-S-right>") nil)
(define-key evil-normal-state-map (kbd "C-k") (foo))
(define-key global-map (kbd "RET") 'newline-and-indent)
(global-set-key [(C-f4)] 'bury-buffer)
(global-set-key [(f6)] 'emms-playlist-mode-go)
(define-key c-mode-map [(tab)] 'company-complete)
(define-key ggtags-mode-map (kbd "C-c g s") 'ggtags-find-other-symbol)
(setq helm-gtags-prefix-key "\C-cg")
(define-key evil-normal-state-map [escape] 'keyboard-quit)
(bind-key "<escape>" 'isearch-cancel isearch-mode-map)
(global-unset-key "\M-:")
Is there a canonical way to define key combinations? If so, where can I read about it, especially for a list of special and modifier keys (tab, escape, return, meta, ctrl, shift, super, Fn, delete)?
edit: This question and the answers below go a lot deeper than the similar question asked here.
.../lisp/bindings.el
and.../lisp/term/ns-win.el
(for OSX).[(C-f4)]
is the obsolete way or as the sources put it, "Lucid-style event type list". Personally, I'd always use thekbd
syntax unless there's something you can't easily represent with it, then you can go for either strings or vectors.