dotfiles/emacs-lisp/keybindings.org
magic_rb a304841f48
emacs: keybinding
Signed-off-by: magic_rb <magic_rb@redalder.org>
2024-11-09 22:15:47 +01:00

4.5 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.

First we need to define a new minor mode.

  (define-minor-mode magic_rb/userbind-mode
    "Minor mode for user keybindings of Magic_RB."
    :lighter " userbind."
    :global t
    :keymap (make-sparse-keymap))

Then we hook our minor mode on meow-mode-hook, but only after meow-mode is loaded.

   (add-hook 'after-init-hook 'magic_rb/userbind-mode)
  (transient-define-prefix magic-quick-ement ()
    "Prefix with ement related commands."
    ["ement"
     ("l" "list rooms" ement-list-rooms)
     ("v" "view room" ement-view-room)
     ("n" "view notifications" ement-notify-switch-to-notifications-buffer)
     ("m" "view mentions" ement-notify-switch-to-mentions-buffer)
     ])

  (transient-define-prefix magic-quick-lsp ()
    "Prefix with LSP related commands."
    ["LSP"
     ("l" "start LSP" lsp)
     ("r" "restart server" lsp-workspace-restart)
     ("s" "stop server" lsp-workspace-shutdown)
     ("e" "execute code action" lsp-execute-code-action)
     ("d" "doc glance" lsp-ui-doc-glance)
     ])

  (transient-define-prefix magic-quick-buffer ()
    "Prefix with buffer related commands."
    ["Buffer"
     ("i" "indent region" indent-region)
     ("c" "comment region" comment-dwim)
     ])

  (transient-define-prefix magic-quick-window ()
    "Prefix with window related commands."
    ["Windows"
     ("t" "move left" windmove-left)
     ("r" "move up" windmove-up)
     ("n" "move down" windmove-down)
     ("s" "move right" windmove-right)
     ("q" "quit" ignore)
     ("a" "ace window" ace-window)
     ])

  (transient-define-prefix magic-quick-popper ()
    "Prefix with popper related commands."
    ["Popper"
     ("c" "cycle popped windows" popper-cycle)
     ("p" "toggle latest popped window" popper-toggle)
     ("t" "toggle window being popped" popper-toggle-type)
     ])

  (transient-define-prefix magic-quick-projectile ()
    "Prefix with projectile related commands."
    ["Projectile"
     ("v" "run vterm" projectile-run-vterm)
     ("m" "version control" projectile-vc)
     ("s" "switch project" projectile-switch-project)
     ])

  (transient-define-prefix magic-quick-consult ()
    "Prefix with consult related commands."
    ["Consult"
     ("f" "find a file" consult-fd)
     ("r" "ripgrep" consult-ripgrep)
     ("l" "find a line" consult-line)
     ("b" "switch buffer" consult-buffer)
     ("y" "yank" consult-yank-from-kill-ring)
     ("e" "goto error" consult-flycheck)
     ])

  (transient-define-prefix magic-quick-org-mode ()
    "Prefix with org-mode related commands."
    ["Org Mode"
     ("f" "find a roam node" org-roam-node-find)
     ("i" "insert a roam node" org-roam-node-insert)
     ("t" "add a tag to the node at point" org-roam-tag-add)
     ("T" "remove a tag from the node at point" org-roam-tag-remove)
     ("r" "add a ref to the node at point" org-roam-ref-add)
     ("R" "remove a ref from the node at point" org-roam-ref-remove)
     ("c" "capture a new node" org-roam-capture)
     ("b" "toggle the backlink buffer" org-roam-buffer-toggle)
     ("a" "show the agenda" org-agenda)
     ])

  (transient-define-prefix org-roam-quick ()
    "Prefix with groups in a grid-like arrangement."
    [
     ("e" "ement.el" magic-quick-ement)
     ("l" "lsp-mode" magic-quick-lsp)
     ("b" "buffers" magic-quick-buffer)
     ("w" "windows" magic-quick-window)
     ("r" "popper" magic-quick-popper)
     ("p" "projectile" magic-quick-projectile)
     ("j" "consult" magic-quick-consult)
     ("o" "org-mode" magic-quick-org-mode)
     ])

  (with-eval-after-load 'meow
    (meow-leader-define-key
     '("o" . org-roam-quick)))
  (general-def
    :keymaps '(magic_rb/userbind-mode-map)
    :prefix "C-c"
    "o" 'magic-quick-org-mode
    "j" 'magic-quick-consult
    "p" 'magic-quick-projectile
    "r" 'magic-quick-popper
    "w" 'magic-quick-window
    "b" 'magic-quick-buffer
    "l" 'magic-quick-lsp
    "e" 'magic-quick-ement

    "M-c" 'tempel-insert
    :keymaps '(special-mode-map)
    :prefix ""
    "q" 'nil
    "k" 'quit-window)

#+RESULTS: