Protesilaos Stavrou (prot) has an excellent video that addresses a problem I often see people asking about. The problem is how to globally set a key binding so that it won’t be overridden. He uses setting Meta+o to other-window as an example to explore the problem.
Prot begins by defining Meta+o in the global map in the usual way:
(define-key global-map (kbd "M-o") 'other-window )
That works well until he tries it in an HTML buffer. In the HTML buffer, Meta+o turns out to be a prefix key for inserting an HTML face command. The problem is that Emacs will use the most specific bindings first. Global bindings are the most general, followed by major mode bindings, and ending with minor mode bindings as the most specific.
Since HTML is a major mode, its keybinding take precedence over the global binding that we set. The answer is to get more specific yet by defining our binding in a minor mode so that it will always have precedence.
Prot shows how to define a minor where we can define our binding and activate it globally so that it’s always available. Of course, once we have this mechanism set up, we can add any number of bindings to our minor mode. Prot demonstrates this by adding a binding that Org uses.
Take a look at Prot’s video for all the details. He’s also included a copy of the file he was working with so you can see everything without worrying about copying it down from the video. The video is 12 minutes, 45 seconds so it should be easy to fit in.