Q:

How to override major mode bindings

Sometimes my global keybindings are overridden by a major mode.  An easy example is the following setting in my init file
(global-set-key (kbd "C-j") 'newline-and-indent)

But annoyingly this keybinding is hidden by the "Lisp Interaction" major mode which is the default mode of the scratch buffer.
When I find myself in a situation where a major mode (or minor mode) is hiding my global keybinding, how can I get it back?
Note: My question is not "How can I bind C-j to newline-and-indent in "Lisp Interaction" mode?"  I am interested in a much more general answer about how to deal with keymaps that clash or user keybindings that get hidden by some major/minor mode.

A:

There is a "shortcut" approach too for the same solution if you don't want to define your own minor mode (that I talk about in my first answer).
You can install the use-package package available from Melpa and make use of bind-key* or bind-keys* macro that's part of the bind-key package that ships with use-package.
From the documentation of bind-key.el:
;; If you want the keybinding to override all minor modes that may also bind
;; the same key, use the `bind-key*' form:
;;
;;   (bind-key* "<C-return>" 'other-window)

;; To bind multiple keys in a `bind-key*' way (to be sure that your bindings
;; will not be overridden by other modes), you may use `bind-keys*' macro:
;;
;;    (bind-keys*
;;     ("C-o" . other-window)
;;     ("C-M-n" . forward-page)
;;     ("C-M-p" . backward-page))

A:

You can define your own minor mode and its key map and have that override all other modes (minor + major). That's exactly why I chose to write my own minor mode. 
Steps to have your key bindings override all bindings:

Defining your own minor mode and key map as shown below.
Activate your minor mode globally
(define-key my-mode-map (kbd "C-j") #'newline-and-indent)

Similarly your other key bindings set in your minor mode will override those in other modes.
I highly recommend reading the blog post by Christopher Wellons on how to write a minor mode. That blog plus the annoyance of having to set multiple key bindings to nil in multiple major and minor modes inspired me to write my own minor mode. 
The best part of using this approach is that when you want to check what the key bindings do in emacs' default configuration, you simply turn off your minor mode; you then turn it back on and you get back your custom key bindings. 
;; Main use is to have my key bindings have the highest priority
;; https://github.com/kaushalmodi/.emacs.d/blob/master/elisp/modi-mode.el

(defvar my-mode-map (make-sparse-keymap)
  "Keymap for `my-mode'.")

;;;###autoload
(define-minor-mode my-mode
  "A minor mode so that my key settings override annoying major modes."
  ;; If init-value is not set to t, this mode does not get enabled in
  ;; `fundamental-mode' buffers even after doing \"(global-my-mode 1)\".
  ;; More info: http://emacs.stackexchange.com/q/16693/115
  :init-value t
  :lighter " my-mode"
  :keymap my-mode-map)

;;;###autoload
(define-globalized-minor-mode global-my-mode my-mode my-mode)

;; https://github.com/jwiegley/use-package/blob/master/bind-key.el
;; The keymaps in `emulation-mode-map-alists' take precedence over
;; `minor-mode-map-alist'
(add-to-list 'emulation-mode-map-alists `((my-mode . ,my-mode-map)))

;; Turn off the minor mode in the minibuffer
(defun turn-off-my-mode ()
  "Turn off my-mode."
  (my-mode -1))
(add-hook 'minibuffer-setup-hook #'turn-off-my-mode)

(provide 'my-mode)

;; Minor mode tutorial: http://nullprogram.com/blog/2013/02/06/

A:

To have a global binding override a major mode binding, simply set the binding to nil in the major mode:
(define-key my-major-mode-map (kbd "C-j") nil)

It's not possible to have the global binding take precedence over all modes in general (otherwise there would be no point in having major modes), but you could hack around it by creating your own minor mode with your most important bindings. Then you would at least have precedence over most (although not necessarily all) modes.

