Created
June 1, 2024 15:23
-
-
Save alexispurslane/fe520a69210fbe5e0462be39c351a370 to your computer and use it in GitHub Desktop.
The basic starter leader-key configuration, for people that want Doom Emacs/Spacemacs like leader keys and don't know where to start. Should only use built-in vanilla Emacs commands!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; Spacemacs/Doom-like evil mode leader key keybindings layer | |
(defun optional/devil-layer () | |
"Define Spacemacs/Doom-style leader keys. This is | |
high-maintinence, as you won't be able to use any of the | |
keybindings that come with any Emacs commands or modes by | |
default, you'll have to bind your own keybindings for all of | |
them. However, this is the most ergonomic and logical from a | |
first-principles point of view." | |
(with-eval-after-load "general" | |
;;;;;; Create the mode-specific leader key mapping function | |
(general-create-definer +core--internal-local-map! | |
:states '(insert emacs visual normal) | |
:keymaps 'override | |
:prefix "SPC m" | |
:global-prefix "M-SPC m") | |
;;;;;; Add mode-specific keybindings | |
(add-hook 'emacs-lisp-mode-hook | |
(lambda () | |
(+core--internal-local-map! | |
"E" #'eval-print-last-sexp | |
"e" #'eval-last-sexp | |
"d" #'eval-defun | |
"b" #'eval-buffer | |
"r" #'eval-region))) | |
(add-hook 'pandoc-mode-hook | |
(lambda () | |
(+core--internal-local-map! | |
"p" #'pandoc-main-hydra/body))) | |
(add-hook 'outline-minor-mode | |
(lambda () | |
(+core--internal-local-map! | |
"j" #'outline-move-subtree-down | |
"k" #'outline-move-subtree-up | |
"h" #'outline-promote | |
"l" #'outline-demote))) | |
(add-hook 'org-mode-hook | |
(lambda () | |
(local-set-key (kbd "RET") #'evil-org-return) | |
(+core--internal-local-map! | |
"L" #'org-insert-link))) | |
;; gobal keybindgs that are truly global | |
(general-create-definer tyrant-def | |
:states '(normal insert motion emacs) | |
:keymaps 'override | |
:prefix "SPC" | |
:non-normal-prefix "M-SPC") | |
;; Define the built-in global keybindings — this is the heart of this editor! | |
(tyrant-def | |
;;;;;; Top level functions | |
"SPC" '(execute-extended-command :wk "M-x") | |
":" '(pp-eval-expression :wk "Eval expression") | |
";" #'project-find-file | |
"u" '(universal-argument :wk "C-u") | |
"C" #'universal-coding-system-argument | |
"O" #'other-window-prefix | |
"r" #'restart-emacs | |
;;;;;; Quit/Session | |
"q" '(nil :wk "quit/session") | |
"qq" #'save-buffers-kill-terminal | |
"qQ" #'kill-emacs | |
"qS" #'server-start | |
"qR" #'recover-session | |
"qd" #'desktop-read | |
"qs" #'desktop-save | |
"qr" #'restart-emacs | |
;;;;;; Files | |
"f" '(nil :wk "file") "fS" '(write-file :wk "Save as ...") | |
"fi" #'auto-insert | |
"ff" #'find-file | |
"fs" #'save-buffer | |
"ft" #'recover-this-file | |
"fT" #'recover-file | |
"fr" #'consult-recent-file | |
"fa" #'outline-show-all | |
"fh" (lambda () (interactive) (outline-hide-sublevels 1)) | |
"ft" #'tab-switch | |
;;;;;; Personal Profile | |
"P" '(nil :wk "profile") | |
"Pf" `(,(lambda () (interactive) (find-file "~/.emacs.d/init.el")) | |
:wk "Open framework config") | |
"Pu" `(,(lambda () (interactive) (find-file "~/.quake.d/user.el")) | |
:wk "Open user config") | |
;;;;;; Buffers | |
"b" '(nil :wk "buffer") | |
"bB" #'switch-to-buffer-other-tab | |
"bb" #'consult-buffer | |
"bI" #'ibuffer | |
"bx" #'bury-buffer | |
"bS" #'save-some-buffers | |
"bM" #'view-echo-area-messages | |
"bk" `(,(lambda () (interactive) (kill-buffer (current-buffer))) | |
:wk "Kill this buffer") | |
"bK" #'kill-buffer | |
"br" '(revert-buffer :wk "Revert") | |
"bR" '(rename-buffer :wk "Rename") | |
"bn" '(switch-to-next-buffer :wk "Next buffer") | |
"bp" '(switch-to-prev-buffer :wk "Previous buffer") | |
;;;;;;; Lines | |
"bl" '(nil :wk "line") | |
"blk" #'keep-lines ;; Will be overwritten with `consult-keep-lines' | |
;;;;;;; Bookmarks | |
"bm" '(nil :wk "bookmark") | |
"bmm" #'bookmark-set | |
"bmd" #'bookmark-delete | |
;;;;;;; Files / Local variables | |
"bv" '(nil :wk "locals") | |
"bvv" '(add-file-local-variable :wk "Add") | |
"bvV" '(delete-file-local-variable :wk "Delete") | |
"bvp" '(add-file-local-variable-prop-line :wk "Add in prop line") | |
"bvP" '(delete-file-local-variable-prop-line :wk "Delete from prop line") | |
"bvd" '(add-dir-local-variable :wk "Add to dir-locals") | |
"bvD" '(delete-dir-local-variable :wk "Delete from dir-locals") | |
;;;;;; Insert | |
"i" '(nil :wk "insert") | |
"iu" '(insert-char :wk "Unicode char") | |
"ip" #'yank-pop ;; Will be overwritten with `consult-yank-pop' | |
"iei" #'emoji-insert | |
"ie+" #'emoji-zoom-increase | |
"ie-" #'emoji-zoom-decrease | |
"ie0" #'emoji-zoom-reset | |
"ied" #'emoji-describe | |
"iel" #'emoji-list | |
"ier" #'emoji-recent | |
"iee" #'emoji-search | |
;;;;;; Window | |
"w" '(nil :wk "window") | |
"wd" #'delete-window | |
"wD" #'delete-windows-on | |
"wo" #'delete-other-windows | |
"wm" #'maximize-window | |
"wu" #'winner-undo | |
"wU" #'winner-redo | |
"wj" #'evil-window-down | |
"wk" #'evil-window-up | |
"wh" #'evil-window-left | |
"wl" #'evil-window-right | |
"ws" #'split-window-vertically | |
"wv" #'split-window-horizontally | |
"ww" #'other-window | |
;;;;;; Applications (Open) | |
"o" '(nil :wk "open") | |
"o-" '(dired :wk "Dired") ;; Will be overwritten if dirvish is used | |
"oT" #'toggle-frame-tab-bar | |
"og" #'gnus-other-frame | |
"o=" #'calc | |
"os" `(,(lambda () (interactive) | |
(let ((new-shell-frame (make-frame))) | |
(select-frame new-shell-frame) | |
(funcall term-preferred-command 'new))) | |
:wk "Open new shell") | |
"oa" #'org-agenda | |
;;;;;; Search | |
"s" '(nil :wk "search") | |
"si" #'imenu | |
"sg" #'grep | |
"sf" #'find | |
;;;;;; Mode specific a.k.a. "local leader" | |
"m" '(nil :wk "mode-specific") | |
;;;;; Version Control | |
"g" '(nil :wk "git/vc") | |
"gg" #'magit | |
;;;;;; Toggle | |
"t" '(nil :wk "toggle") | |
"td" #'toggle-debug-on-error | |
"tr" #'read-only-mode | |
"tl" #'follow-mode | |
"tv" #'visible-mode | |
"tf" #'flymake-mode | |
;;;;;; Language Server | |
"l" '(nil :wk "lsp and flymake") | |
"le" #'eglot | |
"lr" #'eglot-rename | |
"la" #'eglot-code-actions | |
"lx" #'eglot-code-action-extract | |
"lf" #'eglot-code-action-quickfix | |
"l!" #'consult-flymake | |
"ln" #'flymake-goto-next-error | |
"lp" #'flymake-goto-prev-error | |
;;;;;; Debug | |
"d" '(nil :wk "debug") | |
"dG" #'gdb | |
"dd" #'dape | |
;;;;;; Notes | |
"n" '(nil :wk "notes") | |
"ns" #'denote-silo | |
"nc" #'denote | |
"nn" #'consult-notes | |
"ni" #'denote-link-global | |
"nI" #'denote-link-after-creating | |
"nr" #'denote-rename-file | |
"nk" #'denote-keywords-add | |
"nK" #'denote-keywords-remove | |
"nb" #'denote-backlinks | |
"nB" #'denote-find-backlink | |
"nR" #'denote-region | |
;;;;;; Help | |
"h" '(nil :wk "help") | |
"hi" #'info | |
"hg" #'general-describe-keybindings | |
"he" '(nil :wk "elisp/emacs") | |
"hes" #'elisp-index-search | |
"hem" #'info-emacs-manual | |
"hei" #'Info-search | |
"hv" #'describe-variable | |
"hk" #'describe-key | |
"hc" #'describe-command | |
"hf" #'describe-callable | |
"hm" #'describe-keymap | |
"hb" #'describe-bindings | |
"hs" #'describe-symbol | |
"hp" #'describe-package | |
;;;;;; Project | |
"p" '(nil :wk "project") | |
"pp" #'project-switch-project | |
"pc" #'project-compile | |
"pd" #'project-find-dir | |
"pf" #'project-find-file | |
"pk" #'project-kill-buffers | |
"pb" #'project-switch-to-buffer | |
"p-" #'project-dired | |
"px" #'project-execute-extended-command | |
;;;;;;; Compile / Test | |
"pc" #'project-compile | |
;;;;;;; Run | |
"pr" '(nil :wk "run") | |
"prc" #'project-shell-command | |
"prC" #'project-async-shell-command | |
;;;;;;; Forget | |
"pF" '(nil :wk "forget/cleanup") | |
"pFp" #'project-forget-project | |
"pFu" #'project-forget-projects-under | |
;;;;;;; Search / Replace | |
"ps" '(nil :wk "search/replace") | |
"pss" #'project-search | |
"psn" '(fileloop-continue :wk "Next match") | |
"psr" #'project-query-replace-regexp | |
"psf" #'project-find-regexp))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment