I showed you my source code, pls respond
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
4.4 KiB

  1. #+TITLE: Keys
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+PROPERTY: header-args:emacs-lisp :tangle keys.el :comments org
  5. #+PROPERTY: header-args :results silent :eval no-export :comments org
  6. #+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  7. #+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  8. Improve the keyboard experience within Emacs.
  9. * Config
  10. Some of the default keybindings in Emacs really do leave you wondering, for example, when you want to exit a prompt you have to use =C-g=. Offer =ESC= as an alternative to quit (most) prompts, which I have muscle memory for already from literally every program created since 1990.
  11. #+begin_src emacs-lisp
  12. (global-set-key (kbd "<escape>") 'keyboard-escape-quit)
  13. #+end_src
  14. ** Hints
  15. Since Emacs is keyboard driven software, there are a lot of keybindings. Sometimes it's useful to start pressing well-known key combinations, and view the available completions. This behaviour is implemented in the third-party package ~which-key~[fn:1]. It displays the current incomplete keybinding input in a mini-buffer. It also works in the other direction, showing the corresponding keybindings for each command when you run =M-x=.
  16. #+begin_src emacs-lisp
  17. (use-package which-key
  18. :diminish which-key-mode
  19. :custom (which-key-idle-delay dotfiles/idle)
  20. :config (which-key-mode))
  21. #+end_src
  22. ** Leader
  23. If like myself, you started using Emacs using a framework such as ~doom~[fn:2] or ~spacemacs~[fn:3], you probably have a considerable amount of muscle memory developed for using =SPC= as a leader key. In both of the previously mentioned frameworks, the package ~general.el~[fn:4] is used to implement this behaviour. It's a major improvement to the default way of creating custom keybindings in Emacs.
  24. #+begin_src emacs-lisp
  25. (use-package general
  26. :config
  27. (general-create-definer dotfiles/leader
  28. :states '(normal motion)
  29. :keymaps 'override
  30. :prefix dotfiles/leader-key
  31. :global-prefix dotfiles/leader-key-global))
  32. #+end_src
  33. ** Transient
  34. Create transient keybindings with a shared prefix through ~hydra~[fn:5]. This is also used by a number of third-party packages as a completion system. An implementation example is used to scale the font size.
  35. #+begin_src emacs-lisp
  36. (use-package hydra
  37. :defer t)
  38. #+end_src
  39. * Shortcuts
  40. Implement some shortcut bindings, with a significant portion of them cherry picked from ~doom~[fn:2]:
  41. + Close buffers with =SPC c=
  42. + Find files with =SPC . (period)=
  43. + Switch buffers with =SPC , (comma)=
  44. #+begin_src emacs-lisp
  45. (dotfiles/leader
  46. "." '(find-file :which-key "Files")
  47. "," '(switch-buffer :which-key "Buffers")
  48. "c" '(kill-buffer-and-window :which-key "Close"))
  49. #+end_src
  50. ** Managing windows
  51. Screen space is divided into Frames inside of Emacs, manage them behind =SPC w=:
  52. + Swap with =w=
  53. + Close with =c=
  54. + Move with =h,j,k,l=
  55. + Split with =s - <motion>=
  56. #+begin_src emacs-lisp
  57. (dotfiles/leader
  58. "w" '(:ignore t :which-key "Window")
  59. "ww" '(window-swap-states :which-key "Swap")
  60. "wc" '(delete-window :which-key "Close")
  61. "wh" '(windmove-left :which-key "Left")
  62. "wj" '(windmove-down :which-key "Down")
  63. "wk" '(windmove-up :which-key "Up")
  64. "wl" '(windmove-right :which-key "Right")
  65. "ws" '(:ignore t :which-key "Split")
  66. "wsj" '(split-window-below :which-key "Down")
  67. "wsl" '(split-window-right :which-key "Right"))
  68. #+end_src
  69. ** Quitting Emacs
  70. Customize the behaviour of exiting emacs, with keybindings behind =SPC q=:
  71. + Save and quit =q=
  72. + Quit without saving =w=
  73. + Exit the Frame (daemon) =f=
  74. #+begin_src emacs-lisp
  75. (dotfiles/leader
  76. "q" '(:ignore t :which-key "Quit")
  77. "qq" '(save-buffers-kill-emacs :which-key "Save")
  78. "qw" '(kill-emacs :which-key "Now")
  79. "qf" '(delete-frame :which-key "Frame"))
  80. #+end_src
  81. ** Helper Functions
  82. Use the built-in ~describe-*~ functionality of Emacs to quickly access documentation for packages, variables, and functions. Run helper functions with =SPC h=:
  83. + Packages =p=
  84. + Variables =v=
  85. + Functions =f=
  86. #+begin_src emacs-lisp
  87. (dotfiles/leader
  88. "h" '(:ignore t :which-key "Help")
  89. "hp" '(describe-package :which-key "Package")
  90. "hv" '(describe-variable :which-key "Variable")
  91. "hf" '(describe-function :which-key "Function"))
  92. #+end_src
  93. * Footnotes
  94. [fn:1] https://github.com/justbur/emacs-which-key/
  95. [fn:2] https://github.com/hlissner/doom-emacs/
  96. [fn:3] https://spacemacs.org
  97. [fn:4] https://github.com/noctuid/general.el
  98. [fn:5] https://github.com/abo-abo/hydra