Emacs keybindings are hierarchical. Global keybindings are masked by major-mode keybindings, and major-mode keybindings are masked by minor-mode keybindings. When you set global keybindings in your init.el
, they work as long as they don't conflict with any active major or minor modes.
In your case, vhdl-mode
is binding tab
to whatever function it uses for indentation/completion.
How to avoid such conflicts? It's a bit tricky, but you have a few options:
C-c LETTER bindings
By convention (usually, but not always, followed), keybindings of the form C-c <letter>
are reserved for users. That means if you bind something to C-c x
(or any other single letter in place of x
):
(global-set-key (kbd "C-c x") 'my-favorite-function)
it shouldn't have any conflicts with major or minor modes.
F5-F9
Similarly, functions keys 5-9 are reserved for users:
(global-set-key (kbd "<f5>") 'another-cool-function)
Define a new prefix-key
Define a new prefix key to give yourself your own personal area for key bindings:
(define-prefix-command 'my-keymap)
(global-set-key (kbd "<f5>") my-keymap)
(define-key my-keymap "a" 'function-one)
(define-key my-keymap "b" 'function-two)
You can use any key you like for your new prefix key. As long as you use a key that doesn't conflict with a major or minor mode, this gives you a nice way to increase your personal key binding space.
Personally, I use M-<space>
as my prefix key. This means I lose access to the function it is normally bound to, which is just-one-space
. But I add it to the prefix so I can get it back with one extra key-press:
(define-prefix-command 'tws-keymap)
(global-set-key "\M- " tws-keymap)
(define-key tws-keymap " " 'just-one-space)
(define-key tws-keymap "i" 'toggle-window-split)
...
In theory, if I use a mode that rebinds M-<space>
, it will mess up my prefix-map. However, I haven't run into that problem yet.
Define a new minor mode
You can also create your own minor mode just to hold your keybindings, which will prevent any major-modes from hiding them. That's a bit more involved to include here, but it's an option if you know (or want to learn) more elisp.