Though I know how to set a global key-binding in Emacs, I find it hard to even Google out the code for a local (minor-mode specific) key-binding. For instance, I have this code in my .emacs
:
;; PDFLaTeX from AucTeX (global-set-key (kbd "C-c M-p") (lambda () (interactive) (shell-command (concat "pdflatex " buffer-file-name))))
I don't want to set it globally. Is there a function like local-set-key
?
emacs file. To interactively bind keys for all modes, type M-x global-set-key RET key cmd RET . To bind a key just in the current major mode, type M-x local-set-key RET key cmd RET . See Key Bindings in The GNU Emacs Manual .
To reassign a keySelect the Start button, and then select Microsoft Mouse and Keyboard Center. From the displayed list of key names, select the key that you want to reassign. In the command list of the key that you want to reassign, select a command.
Hold "Ctrl-Alt" and press a key to bind the program to the "Ctrl-Alt-[Key]" hotkey.
Setting the key binding to nil is indeed the way to unbind it. You just need to do that in the right map. Using C-h M-k ( describe-keymap ), from library help-fns+. el will give you a human-readable list of the bindings in a given keymap (bound to a keymap variable, such as global-map .
I use the following:
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "C-0") #'run-latexmk)))
to have a bind defined for LaTeX mode alone.
To bind a key in a mode, you need to wait for the mode to be loaded before defining the key. One could require the mode, or use eval-after-load
(eval-after-load 'latex '(define-key LaTeX-mode-map [(tab)] 'outline-cycle))
Don't forget either '
—eval-after-load
is not a macro, so it needs them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With