nixos-dotfiles

nixos-dotfiles

https://git.tonybtw.com/nixos-dotfiles.git git://git.tonybtw.com/nixos-dotfiles.git
4,518 bytes raw
1
;;; keybinds.el --- All keybindings -*- lexical-binding: t -*-
2
3
;; C-c to escape insert mode
4
(define-key evil-insert-state-map (kbd "C-c") 'evil-normal-state)
5
6
;;; Global keys
7
(global-set-key (kbd "M-x") 'execute-extended-command)
8
(global-set-key (kbd "C-x b") 'consult-buffer)
9
(global-set-key (kbd "C-c m s") 'magit-status)
10
(global-set-key (kbd "C-c m l") 'magit-log)
11
12
;;; Multiple cursors
13
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
14
(global-set-key (kbd "C->")         'mc/mark-next-like-this)
15
(global-set-key (kbd "C-<")         'mc/mark-previous-like-this)
16
(global-set-key (kbd "C-c C-<")     'mc/mark-all-like-this)
17
(global-set-key (kbd "C-\"")        'mc/skip-to-next-like-this)
18
(global-set-key (kbd "C-:")         'mc/skip-to-previous-like-this)
19
20
;;; Move text
21
(global-set-key (kbd "M-p") 'move-text-up)
22
(global-set-key (kbd "M-n") 'move-text-down)
23
24
;;; Dired evil bindings
25
(with-eval-after-load 'dired
26
  (evil-define-key 'normal dired-mode-map
27
    "." 'dired-create-empty-file
28
    "h" 'dired-up-directory
29
    "l" 'dired-find-file
30
    "n" 'evil-search-next
31
    "N" 'evil-search-previous))
32
33
;;; Org mode evil bindings
34
(defun my/org-heading-has-checkbox-p ()
35
  "Check if current heading has [ ] or [X] checkbox."
36
  (save-excursion
37
    (beginning-of-line)
38
    (looking-at "^\\*+\\s-+\\[[ X-]\\]")))
39
40
(defun my/org-update-parent-cookie ()
41
  "Update parent heading's [/] or [n/m] cookie by counting child heading checkboxes."
42
  (save-excursion
43
    (when (org-up-heading-safe)
44
      (let ((start (point))
45
            (end (save-excursion (org-end-of-subtree t) (point)))
46
            (level (org-current-level))
47
            (checked 0)
48
            (total 0))
49
        ;; Count direct child headings with checkboxes
50
        (save-excursion
51
          (while (re-search-forward (format "^\\*\\{%d\\}\\s-+\\[\\([ X-]\\)\\]" (1+ level)) end t)
52
            (setq total (1+ total))
53
            (when (string= (match-string 1) "X")
54
              (setq checked (1+ checked)))))
55
        ;; Update the cookie in parent heading
56
        (beginning-of-line)
57
        (when (re-search-forward "\\[\\([0-9]*/[0-9]*\\|/\\)\\]" (line-end-position) t)
58
          (replace-match (format "[%d/%d]" checked total) t t))))))
59
60
(defun my/org-toggle-heading-checkbox ()
61
  "Toggle [ ] <-> [X] in current heading and update parent cookie."
62
  (save-excursion
63
    (beginning-of-line)
64
    (when (re-search-forward "\\[\\([ X-]\\)\\]" (line-end-position) t)
65
      (replace-match (if (string= (match-string 1) " ") "[X]" "[ ]") t t)))
66
  (my/org-update-parent-cookie))
67
68
(defun my/org-dwim-at-point ()
69
  "Do-what-I-mean at point: toggle checkbox, follow link, or cycle TODO."
70
  (interactive)
71
  (cond
72
   ;; Heading with [ ] or [X]
73
   ((my/org-heading-has-checkbox-p)
74
    (my/org-toggle-heading-checkbox))
75
   ;; List checkbox
76
   ((org-at-item-checkbox-p)
77
    (org-toggle-checkbox))
78
   ;; Link
79
   ((org-in-regexp org-link-any-re)
80
    (org-open-at-point))
81
   ;; Regular TODO heading
82
   ((org-at-heading-p)
83
    (org-todo))
84
   (t (org-return))))
85
86
(with-eval-after-load 'org
87
  (evil-define-key 'normal org-mode-map
88
    (kbd "RET") 'my/org-dwim-at-point
89
    (kbd "<return>") 'my/org-dwim-at-point
90
    "t" 'org-todo))
91
92
;;; LSP keybindings
93
(with-eval-after-load 'eglot
94
  (evil-define-key 'normal eglot-mode-map
95
    "K" 'eldoc-box-help-at-point
96
    "gd" 'xref-find-definitions
97
    "gr" 'xref-find-references))
98
99
;;; Leader keybindings (SPC)
100
(evil-leader/set-key
101
  ;; files
102
  "ff" 'my/telescope-find-files
103
  "fF" 'my/fzf-find-file
104
  "fg" 'my/consult-ripgrep
105
  "fs" 'my/consult-ripgrep-symbol
106
  "fo" 'consult-recent-file
107
  "fl" 'consult-line
108
  "fi" 'my/find-emacs-config
109
  "fp" 'my/switch-project
110
  ;; buffers
111
  "bb" 'consult-buffer
112
  "fb" 'consult-buffer
113
  "bp" 'previous-buffer
114
  "bn" 'next-buffer
115
  "bd" 'kill-current-buffer
116
  "bm" 'ibuffer
117
  ;; custom
118
  "cr" 'my/set-base-dir
119
  "cd" (lambda () (interactive) (dired (file-name-directory (or buffer-file-name default-directory))))
120
  "cl" 'my/close-popup-window
121
  "cn" 'next-error
122
  "cp" 'previous-error
123
  "cc" 'compile
124
  "cm" 'recompile
125
  "cb" (lambda () (interactive) (compile "bear -- make"))
126
  ;; magit
127
  "ms" 'magit-status
128
  "ml" 'magit-log
129
  ;; ssh/servers
130
  ; "st" 'my/connect-tonydev
131
  ;; terminal
132
  "to" 'my/vterm-here
133
  ;; window
134
  "wv" 'split-window-right
135
  "ws" 'split-window-below
136
  "wd" 'delete-window
137
  "wh" 'evil-window-left
138
  "wj" 'evil-window-down
139
  "wk" 'evil-window-up
140
  "wl" 'evil-window-right
141
  ;; reformat
142
  "qq" 'my/reformat-parenthesized-content
143
  ;; ERC
144
  "ec" 'my/erc-connect-libera)