Skip to main content

9.2.3 Default Bindings

user option magit-define-global-key-bindings

This option controls whether some Magit commands are automatically bound in the global keymap even before Magit is used for the first time in the current session.

If this variable is non-nil, which it is by default, then the following bindings may be added to the global keymap.

C-x gmagit-status
C-x M-gmagit-dispatch
C-c M-gmagit-file-dispatch

These bindings may be added when after-init-hook is run. Each binding is added if and only if at that time no other key is bound to the same command and no other command is bound to the same key. In other words we try to avoid adding bindings that are unnecessary, as well as bindings that conflict with other bindings.

Adding the above bindings is delayed until after-init-hook is called to allow users to set the variable anywhere in their init file (without having to make sure to do so before magit is loaded or autoloaded) and to increase the likelihood that all the potentially conflicting user bindings have already been added.

To set this variable use either setq or the Custom interface. Do not use the function customize-set-variable because doing that would cause Magit to be loaded immediately when that form is evaluated (this differs from custom-set-variables, which doesn’t load the libraries that define the customized variables).

Setting this variable to nil has no effect if that is done after the key bindings have already been added.

We recommend that you bind C-c g instead of C-c M-g to magit-file-dispatch. The former is a much better binding but the C-c <letter> namespace is strictly reserved for users; preventing Magit from using it by default.

(global-set-key (kbd "C-c g") 'magit-file-dispatch)

Also see Commands for Buffers Visiting Files and (elisp)Key Binding Conventions.