is it possible to define key bindings at one place in an init file? something like:
(define-key-bindings '(("C-x M-f" 'fly) ("C-x M-k" 'run) ...))
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
If you are open to installing a package, give
use-package (also available on Melpa) a try, which comes with the
use-package installed, you can do something like below:
(bind-keys :map MINOR-MODE-MAP ; if this line is removed, bindings happen in `global-map' ; else they happen in MINOR-MODE-MAP ("C-x M-f" . fly) ("C-x M-k" . run))
There are more variants of
bind-key* and even
unbind-key. Check out the documentation in the header of
bind-key.el to learn more.
The added benefit of using
bind-keys (and family) is that you can see a summary of all your personal keybindings currently in effect using
M-x describe-personal-keybindings. That will also tell you if you've overridden a pre-bound key using
bind-keys (and family).
Yes, of course.
(defun define-key-bindings (bindings &optional keymap) (unless keymap (setq keymap global-map)) (dolist (bdg bindings) (define-key keymap (kbd (car bdg)) (cadr bdg)))) (define-key-bindings '(("C-x M-f" fly) ("C-x M-k" run)))
(Drop the quote marks before the command names - not needed.)