I want to retain all Emacs original key binding in Evil insert mode, but I want to rebind some of them for cases when evil-mode is not enabled for some reason (in specific buffers). For example, I want to map M-q to save-buffers-kill-terminal to only work in all modes except Evil-insert-mode where is should do what the original Emacs key binding does (fill-paragraph). How do I achieve this?
0
votes
1 Answers
2
votes
To make M-q execute save-buffers-kill-terminal by default, you will want to change M-q's global keybinding:
(global-set-key (kbd "M-q") 'save-buffers-kill-terminal)
But, remember, global keybindings are overridden by mode-specific bindings. In fact, we are going to take advantage of this:
To make a special exception for M-q in Evil-mode when inserting, add a specific keybinding for fill-paragraph into evil-insert-state's keybinding "map":
(define-key evil-insert-state-map (kbd "M-q") 'fill-paragraph)
This one will override the global binding, and will only work in Evil-mode's insert state.
Adding those two lines to your .emacs configuration file should do the trick.