Set custom keybinding for specific Emacs mode

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.


You need to identify the key map for that mode (for example, LaTeX-mode-map) and use the function define-key. As an example, along with activating outline-minor-mode within LaTeX mode, I have:

  (define-key LaTeX-mode-map [(tab)] 'outline-cycle))

In this case the major mode (LaTeX) holds the key binding, but there is also an outline-minor-mode-map.