dotfiles/emacs-lisp/keybindings.org
main c1dc0c1d7f
Move keybindings related Emacs config to separate file
Signed-off-by: main <magic_rb@redalder.org>
2022-04-15 09:50:18 +02:00

4.2 KiB

Keybindings

This file contains all keybindings of my Emacs configuration. I chose to put them all into one file for easy reference and also cross package consistency is easier to ensure when you have everything on one screen.

We need to define a little predicate thing, which allows us to toggle on and off all the modifications we make on a global emacs wide basis.

  (defvar magic_rb-koy-compat-p t "Whether k-o-y layout compatibility should be active.")

In general, we bind special, custom keybindings to the prefix key, it's KOY specific, but it works.

Evil Mode

These are the keybinding related to evil mode, they're split into the primary group and into any package-compatibility keybindings.

Primary

First we need to define a new minor mode, that we can toggle, to disable the edits we make when necessary.

  (define-minor-mode magic_rb-koy-evil-mode
    "Enable koy compatibility for Evil."
    :lighter " koy"
    :keymap (make-sparse-keymap)
    (evil-normalize-keymaps))

Then we hook our minor mode on evil-mode-hook and evil-local-mode-hook, but only after evil-mode is loaded.

  (with-eval-after-load 'evil
   (add-hook 'evil-mode-hook 'magic_rb-koy-evil-mode)
   (add-hook 'evil-local-mode-hook 'magic_rb-koy-evil-mode))

Quick access leader

This is a quick access leader which opens menu's and things. It may be worth moving out the window movements. I'm still debating whether SPC is the best leader, it has some issuas.

  (general-def
    :prefix "SPC"
    :states '(normal motion visual)
    ""  nil
    "t" 'evil-window-left
    "r" 'evil-window-up
    "n" 'evil-window-down
    "s" 'evil-window-right

    "T" 'evil-window-left
    "R" 'evil-window-up
    "N" 'evil-window-down
    "S" 'evil-window-right

    "Y" 'treemacs
    "y" 'treemacs-select-window
    "a" 'treemacs-switch-workspace
    "A" 'treemacs-edit-workspaces

    "v" 'vterm
    "m" 'magit

    "h" 'org-agenda
    "i" 'org-roam-node-find
    "ä" 'org-roam-capture
    "," 'org-roam-buffer-toggle

    "o" 'lsp-execute-code-action)

Evil KOY fixups

KOY requires some changes, mainly around making trns available as movement keys like hjkl.

  (general-def
    :states '(motion normal visual)
    :predicate 'magic_rb-koy-compat-p
    :keymaps 'magic_rb-koy-evil-mode-map
    "t" 'evil-backward-char
    "T" 'evil-first-non-blank
    "r" 'evil-previous-visual-line
    "n" 'evil-next-visual-line
    "s" 'evil-forward-char
    "S" 'evil-end-of-line

    "h" 'evil-find-char-to
    "H" 'evil-find-char-to-backward
    "j" 'evil-replace
    "J" 'evil-join
    "k" 'evil-search-next
    "K" 'evil-search-previous
    "l" 'evil-substitute
    "L" 'evil-change-whole-line)

In insert mode we want to be able to press jj in rapid succession to exit back into normal mode.

  (general-def
    :states '(insert)
    :predicate 'magic_rb-koy-compat-p
    :keymaps 'magic_rb-koy-evil-mode-map
    "j" (general-key-dispatch 'self-insert-command
          :timeout 0.25
          "j" 'evil-normal-state))

Quick Accessors

  (define-minor-mode magic_rb-accessor-mode
    "Enable accessors."
    :lighter " accessors"
    :keymap (make-sparse-keymap)
    :global t
    (evil-normalize-keymaps))

  (magic_rb-accessor-mode)

  (general-def
    :keymap 'magic_rb-accessor-mode-map
    :prefix "•"
    "" nil
    "•" '(insert "•"))

AVY

Avy is cool, it's a "I'm looking at where I wanna jump to, so jump there." kind of package.

  (general-def
    :keymap 'magic_rb-accessor-mode-map
    :prefix "•"
    "z" 'avy-goto-char-timer)

Consult

Consult has cool file switching utililties, like consult-ripgrep.

  (general-def
    :keymap 'magic_rb-accessor-mode-map
    :prefix "•"
    "r" 'consult-ripgrep
    "f" 'consult-find
    "l" 'consult-line)

#+RESULTS: