;; Three ways to bind "cntl-c c" to comment-region ;; Single quote (bind-key "C-c c" 'comment-region c-mode-map) ;; Function quote (bind-key "C-c c" #'comment-region c-mode-map); maybe better? ;; ;; My favorite (bind-keys :c-mode-map ("C-c c" . comment-region) ... )I usually prefer to use bind-keys to organize all my personalized key bindings for each keymap together.
(bind-keys :map global-mapQuietly binds the key accidentally-forgot-to-load. If you forgot to load it then you will not notice until you try typing C-c m, producing the error message... ("C-c m" . accidentally-forgot-to-load) )
Arguably this is reasonable behavior; it may be convenient to be able to defer the definition of a command until after the keymap is set up.
In any case, please be aware that bind-key does not check if commands are defined.
Here is an example from my own use of emacs.
After many years of using C-v with the default binding of
scroll-up, I decided I wanted to use that for view-mode; and use
either the PgDn key or C-. for scroll-up.
However after years of using C-v for scroll-up, I kept typing
it as a habit, and found myself confused because I was unconsciously
switching buffers into view-mode.
The strategy I took to ease the pain of transition was to first temporarily unbind C-v entirely with:
(bind-key "C-v" 'ignore); changes global-mapto loosen the association between C-v and scroll-up, and only later add the new association between C-v and view-mode.
Fortunately it is easy to look up the default key binding. A fail-safe method is to use launch a new emacs process with the -Q flag which tells emacs to skip user init files.
% emacs -Q & ;; Then use M-x to call `describe-key' or `where-is', etc.
If you use the bind-key package to do all of your key binding personalization, the command describe-personal-keybindings can also be very useful.