-
Notifications
You must be signed in to change notification settings - Fork 23
/
init-evil.el
275 lines (247 loc) · 7.91 KB
/
init-evil.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
;;; init-evil.el --- Bring vim back -*- lexical-binding: t -*-
;;; Commentary:
;;
;;; Code:
(require 'init-funcs)
(require 'init-macros)
(use-package evil
:ensure t
:init
(setq evil-disable-insert-state-bindings t)
(setq evil-want-Y-yank-to-eol t)
:hook (after-init . evil-mode)
;; Don't quit Emacs on `:q'.
;;
;; Rebind `f'/`s' to mimic `evil-snipe'.
:bind (([remap evil-quit] . kill-current-buffer)
:map evil-motion-state-map
("f" . evil-avy-goto-char-in-line)
:map evil-normal-state-map
("s" . evil-avy-goto-char-timer))
:config
;; Silence line out of range error.
(shut-up! #'evil-indent)
:custom
;; undo will never freeze my Emacs
(evil-undo-system 'undo-redo)
;; Switch to the new window after splitting
(evil-split-window-below t)
(evil-vsplit-window-right t)
(evil-ex-complete-emacs-commands nil)
(evil-ex-interactive-search-highlight 'selected-window)
;; when `visual-line-mode' enabled, exchange j/k with gj/gk
(evil-respect-visual-line-mode t)
(evil-want-integration t)
(evil-want-keybinding nil)
(evil-want-fine-undo t)
(evil-want-C-g-bindings t)
(evil-want-abbrev-expand-on-insert-exit nil)
(evil-symbol-word-search t))
(use-package evil-surround
:ensure t
:hook (after-init . global-evil-surround-mode))
(use-package evil-collection
:ensure t
:hook (evil-mode . evil-collection-init)
:bind (([remap evil-show-marks] . evil-collection-consult-mark)
([remap evil-show-jumps] . evil-collection-consult-jump-list))
:config
;; Make `evil-collection-consult-mark' and `evil-collection-consult-jump-list'
;; immediately available.
(evil-collection-require 'consult)
:custom
(evil-collection-setup-debugger-keys nil)
(evil-collection-calendar-want-org-bindings t)
(evil-collection-unimpaired-want-repeat-mode-integration t))
;; evil leader map
(use-package evil
:ensure nil
:config
(with-no-warnings
;; We use "SPC" as the leader key, "SPC m" as the localleader key. Due to the
;; limitation of `evil-set-leader', we can't easily set localleader key with
;;
;; ``` elisp
;; (evil-set-leader 'normal (kbd "SPC m") :localleader)
;; ```
;;
;; An error is prompted:
;;
;; ``` elisp
;; (error "Key sequence SPC m starts with non-prefix key SPC")
;; ```
;;
;; If you know how to fix that, let me know. Thanks.
(evil-set-leader 'normal (kbd "SPC"))
(evil-set-leader 'normal (kbd "<leader>m") :localleader)
(defun define-leader-key (state map localleader &rest bindings)
"Define leader key in MAP when STATE, a wrapper for
`evil-define-key*'. All BINDINGS are prefixed with \"<leader>\"
if LOCALLEADER is nil, otherwise \"<localleader>\"."
(cl-assert (cl-evenp (length bindings)))
(let ((prefix (if localleader "<localleader>" "<leader>"))
wk-replacements)
(while bindings
(let ((key (pop bindings))
(def (pop bindings)))
(when (symbolp def)
(evil-define-key* state map (kbd (concat prefix key)) def))
;; Save which-key (key . replacement).
(pcase def
(`(:wk ,replacement)
(push (cons (concat "SPC " key) replacement) wk-replacements)))))
;; which-key integration.
;; XXX: replacement for localleader NOT supported.
(cl-loop for (key . replacement) in wk-replacements
unless localleader
do (which-key-add-key-based-replacements key replacement))))
(define-leader-key 'normal 'global nil
;; SPC, quit minibuffer.
"SPC" 'keyboard-escape-quit
;; Clear highlights
"S-SPC" 'lazy-highlight-cleanup
;; Resume
"'" 'vertico-repeat
;; file
"f" '(:wk "files")
"ff" 'find-file
"fF" 'find-file-other-window
"f/" 'find-file-other-window
"fC" '+copy-current-file
"fD" '+delete-current-file
"fy" '+copy-current-filename
"fR" '+rename-current-file
"fr" 'recentf-open-files
"fl" 'find-file-literally
"fj" 'dired-jump
"fJ" 'dired-jump-other-window
;; buffer & bookmark
"b" '(:wk "bufmark")
"bb" 'switch-to-buffer
"bB" 'switch-to-buffer-other-window
"bc" 'clone-indirect-buffer
"bC" 'clone-indirect-buffer-other-window
"by" '+copy-current-buffer-name
"bv" 'revert-buffer-quick
"bx" 'scratch-buffer
"bz" 'bury-buffer
;; --------------
"bm" 'bookmark-set
"bM" 'bookmark-set-no-overwrite
"bi" 'bookmark-insert
"br" 'bookmark-rename
"bd" 'bookmark-delete
"bw" 'bookmark-write
"bj" 'bookmark-jump
"bJ" 'bookmark-jump-other-window
"bl" 'bookmark-bmenu-list
"bs" 'bookmark-save
;; code
"c" '(:wk "code")
"cd" 'rmsbolt-compile
"cc" 'compile
"cC" 'recompile
"ck" 'kill-compilation
"cw" 'delete-trailing-whitespace
"cx" 'quickrun
;; window
"w" 'evil-window-map
"wx" 'kill-buffer-and-window
"wu" '+transient-tab-bar-history
"w-" 'split-window-vertically
"w/" 'split-window-horizontally
;; tab
"t" '(:wk "tab")
"t9" 'tab-bar-switch-to-last-tab
"tc" 'tab-bar-close-tab
"tC" 'tab-bar-close-group-tabs
"tg" 'tab-bar-change-tab-group
"ti" 'tab-switcher
"tn" 'tab-bar-new-tab
"to" 'tab-bar-close-other-tabs
"tt" 'tab-bar-switch-to-tab
"tp" 'tab-bar-switch-to-recent-tab
"tr" 'tab-bar-rename-tab
;; search
"s" '(:wk "search")
"sj" 'evil-show-jumps
"sm" 'evil-show-marks
"sr" 'evil-show-registers
"si" 'imenu
"sp" 'consult-ripgrep
"ss" 'consult-line
;; project
"p" 'projectile-command-map
;; app
"a" '(:wk "app")
"aa" 'org-agenda
"ac" 'calendar
"ag" 'gnus
"ai" 'rcirc
;; open
"o" '(:wk "open")
"oc" 'org-capture
"ol" 'org-store-link
"ot" 'ansi-term
"oe" 'eshell
"os" 'shell)
(with-eval-after-load 'org
(define-leader-key 'normal org-mode-map :localleader
"." 'org-goto
"a" 'org-archive-subtree
"d" 'org-deadline
"e" 'org-set-effort
"f" 'org-footnote-action
"l" 'org-lint
"o" 'org-toggle-ordered-property
"p" 'org-set-property
"q" 'org-set-tags-command
"r" 'org-refile
"s" 'org-schedule
"t" 'org-todo
"T" 'org-todo-list
;; babel
"bp" 'org-babel-previous-src-block
"bn" 'org-babel-next-src-block
"be" 'org-babel-expand-src-block
"bg" 'org-babel-goto-named-src-block
"bs" 'org-babel-execute-subtree
"bb" 'org-babel-execute-buffer
"bt" 'org-babel-tangle
"bf" 'org-babel-tangle-file
"bc" 'org-babel-check-src-block
"bi" 'org-babel-insert-header-arg
"bI" 'org-babel-view-src-block-info
"bk" 'org-babel-remove-result-one-or-many
;; clock
"cc" 'org-clock-in
"cC" 'org-clock-out
"cd" 'org-clock-mark-default-task
"ce" 'org-clock-modify-effort-estimate
"cg" 'org-clock-goto
"cl" 'org-clock-in-last
"cr" 'org-clock-report
"cs" 'org-clock-display
"cx" 'org-clock-cancel
"c=" 'org-clock-timestamps-up
"c-" 'org-clock-timestamps-down
;; insert
"id" 'org-insert-drawer
"in" 'org-add-note
"it" 'org-time-stamp-inactive
"iT" 'org-time-stamp))
(with-eval-after-load 'elisp-mode
(dolist (keymap (list emacs-lisp-mode-map lisp-interaction-mode-map))
(define-leader-key 'normal keymap :localleader
"i" 'info-lookup-symbol
;; eval
"eb" 'eval-buffer
"ed" 'eval-defun
"ee" 'eval-last-sexp
"el" 'load-library
;; goto
"gf" 'find-function
"gv" 'find-variable
"gl" 'find-library)))))
(provide 'init-evil)
;;; init-evil.el ends here