Global-set-key, but exclude certain modes

I'm trying to create a new binding key that will work fine in all modes except one, where it conflicts with another. For instance:

(global-set-key (kbd "<CS-down>") 'move-line-down) 

Is there a simple way (without setting it for certain local modes) to make it global, excluding a specific mode?

+4
source share
2 answers

You can add a function in the after-change-major-mode-hook that would set the key in the current local layout, with the exception of special modes that you would like to avoid.

+1
source

If you want to exclude one specific mode, you can do the following:

 (global-set-key (kbd "<CS-down>") 'move-line-down) 

to make it available worldwide, and

 (define-key KEYMAP (kbd "<CS-down>") nil) 

exclude one mode where KEYMAP is the name of the mode name followed by a "mode map" (for example, ess-mode-map). You can also bind the original to the key instead of nil .

0
source

All Articles