Skip to main content
deleted 612 characters in body
Source Link
Tyler
  • 22.8k
  • 1
  • 56
  • 95

I think this is a duplicate, but I can't flag it while it has a bounty.Update:

The usualSince you're using a Hydra, I think the best way to create a keybinding that applies in all buffers and doesn't get shadowed by bindings of any other modesdo this is to create your owna minor mode, and putthen define the keybinding therehydra in that minor-mode.

Here's the duplicate that answers this, from @kaushalmodi:Start by creating your minor mode as described in this answer.

You can installThen you just need to define the use-package package available from Melpa and make use of bind-key* or bind-keys* macro that's part ofhydra in the bindmode-key packagemap for that ships with use-package.

From the documentation of bind-key.elmode:

;; 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))

(defhydra python-indent (my-mode-map "C-c")
  "Adjust python indentation."
  (">" python-indent-shift-right "right")
  ("<" python-indent-shift-left "left"))

Original Source. See also other answers at that link for alternatives Once you've run all this code, you can turn on my-mode, and you should have access to your keybinding in all buffers.

I think this is a duplicate, but I can't flag it while it has a bounty.

The usual way to create a keybinding that applies in all buffers and doesn't get shadowed by bindings of any other modes is to create your own minor mode and put the keybinding there.

Here's the duplicate that answers this, from @kaushalmodi:

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))

Original Source. See also other answers at that link for alternatives.

Update:

Since you're using a Hydra, I think the best way to do this is to create a minor mode, and then define the hydra in that minor-mode.

Start by creating your minor mode as described in this answer.

Then you just need to define the hydra in the mode-map for that mode:

(defhydra python-indent (my-mode-map "C-c")
  "Adjust python indentation."
  (">" python-indent-shift-right "right")
  ("<" python-indent-shift-left "left"))

Once you've run all this code, you can turn on my-mode, and you should have access to your keybinding in all buffers.

Bounty Ended with 50 reputation awarded by alper
Source Link
Tyler
  • 22.8k
  • 1
  • 56
  • 95

I think this is a duplicate, but I can't flag it while it has a bounty.

The usual way to create a keybinding that applies in all buffers and doesn't get shadowed by bindings of any other modes is to create your own minor mode and put the keybinding there.

Here's the duplicate that answers this, from @kaushalmodi:

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))

Original Source. See also other answers at that link for alternatives.