forked from doomemacs/doomemacs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
+evil-bindings.el
919 lines (838 loc) · 42 KB
/
+evil-bindings.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
;;; config/default/+bindings.el -*- lexical-binding: t; -*-
;; This file defines a Spacemacs-esque keybinding scheme
;; Don't let evil-collection interfere with certain keys
(setq evil-collection-key-blacklist
(list "gd" "gf" "K" "[" "]" "gz" "<escape>"
doom-leader-key doom-localleader-key
doom-leader-alt-key doom-localleader-alt-key))
(defadvice! +default-evil-collection-disable-blacklist-a (orig-fn)
:around #'evil-collection-vterm-toggle-send-escape ; allow binding to ESC
(let (evil-collection-key-blacklist)
(apply orig-fn)))
;;
;;; Global keybindings
(map! (:map override
;; A little sandbox to run code in
"M-;" #'eval-expression
"A-;" #'eval-expression)
;; Smart tab, these will only work in GUI Emacs
:i [tab] (general-predicate-dispatch nil ; fall back to nearest keymap
(and (featurep! :editor snippets)
(bound-and-true-p yas-minor-mode)
(yas-maybe-expand-abbrev-key-filter 'yas-expand))
'yas-expand
(and (featurep! :completion company +tng)
(+company-has-completion-p))
'+company/complete)
:n [tab] (general-predicate-dispatch nil
(and (featurep! :editor fold)
(save-excursion (end-of-line) (invisible-p (point))))
'+fold/toggle
(fboundp 'evil-jump-item)
'evil-jump-item)
:v [tab] (general-predicate-dispatch nil
(and (bound-and-true-p yas-minor-mode)
(or (eq evil-visual-selection 'line)
(not (memq (char-after) (list ?\( ?\[ ?\{ ?\} ?\] ?\))))))
'yas-insert-snippet
(fboundp 'evil-jump-item)
'evil-jump-item)
;; Smarter newlines
:i [remap newline] #'newline-and-indent ; auto-indent on newline
:i "C-j" #'+default/newline ; default behavior
(:after vc-annotate
:map vc-annotate-mode-map
[remap quit-window] #'kill-current-buffer)
(:map (help-mode-map helpful-mode-map)
:n "o" 'ace-link-help)
;; misc
:n "C-S-f" #'toggle-frame-fullscreen
:n "C-+" #'doom/reset-font-size
:n "C-=" #'doom/increase-font-size
:n "C--" #'doom/decrease-font-size
;; ported from vim
:m "]m" #'+evil/next-beginning-of-method
:m "[m" #'+evil/previous-beginning-of-method
:m "]M" #'+evil/next-end-of-method
:m "[M" #'+evil/previous-end-of-method
:m "]#" #'+evil/next-preproc-directive
:m "[#" #'+evil/previous-preproc-directive
:m "]*" #'+evil/next-comment
:m "[*" #'+evil/previous-comment
:m "]\\" #'+evil/next-comment
:m "[\\" #'+evil/previous-comment
:nv "z=" #'flyspell-correct-word-generic
:v "@" #'+evil:apply-macro
;; ported from vim-unimpaired
:n "] SPC" #'+evil/insert-newline-below
:n "[ SPC" #'+evil/insert-newline-above
:n "]b" #'next-buffer
:n "[b" #'previous-buffer
:n "]f" #'+evil/next-file
:n "[f" #'+evil/previous-file
:m "]u" #'+evil:url-encode
:m "[u" #'+evil:url-decode
:m "]y" #'+evil:c-string-encode
:m "[y" #'+evil:c-string-decode
;; NOTE hl-todo-{next,previous} have ]t/[t, use ]F/[F instead
;; NOTE {next,previous}-error have ]e/[e, use ddp/ddP or gx instead
(:when (featurep! :lang web)
:m "]x" #'+web:encode-html-entities
:m "[x" #'+web:decode-html-entities)
;; custom vim-unmpaired-esque keys
:m "]a" #'evil-forward-arg
:m "[a" #'evil-backward-arg
:m "]e" #'next-error
:m "[e" #'previous-error
:n "]F" #'+evil/next-frame
:n "[F" #'+evil/previous-frame
:m "]h" #'outline-next-visible-heading
:m "[h" #'outline-previous-visible-heading
:n "[o" #'+evil/insert-newline-above
:n "]o" #'+evil/insert-newline-below
:n "gp" #'+evil/reselect-paste
:v "gp" #'+evil/paste-preserve-register
:nv "g@" #'+evil:apply-macro
:nv "gc" #'evil-commentary
:nv "gx" #'evil-exchange
:n "g=" #'evil-numbers/inc-at-pt
:n "g-" #'evil-numbers/dec-at-pt
:v "g=" #'evil-numbers/inc-at-pt-incremental
:v "g-" #'evil-numbers/dec-at-pt-incremental
:v "g+" #'evil-numbers/inc-at-pt
;; custom evil keybinds
:n "zx" #'kill-current-buffer
:n "ZX" #'bury-buffer
;; repeat in visual mode (FIXME buggy)
:v "." #'+evil:apply-macro
;; don't leave visual mode after shifting
:v "<" #'+evil/visual-dedent ; vnoremap < <gv
:v ">" #'+evil/visual-indent ; vnoremap > >gv
;; window management (prefix "C-w")
(:map evil-window-map
;; Navigation
"C-h" #'evil-window-left
"C-j" #'evil-window-down
"C-k" #'evil-window-up
"C-l" #'evil-window-right
"C-w" #'other-window
;; Swapping windows
"H" #'+evil/window-move-left
"J" #'+evil/window-move-down
"K" #'+evil/window-move-up
"L" #'+evil/window-move-right
"C-S-w" #'ace-swap-window
;; Window undo/redo
(:prefix "m"
"m" #'doom/window-maximize-buffer
"v" #'doom/window-maximize-vertically
"s" #'doom/window-maximize-horizontally)
"u" #'winner-undo
"C-u" #'winner-undo
"C-r" #'winner-redo
"o" #'doom/window-enlargen
;; Delete window
"C-C" #'ace-delete-window)
;; Plugins
;; evil-easymotion
:m "gs" #'+evil/easymotion ; lazy-load `evil-easymotion'
(:after evil-easymotion
:map evilem-map
"a" (evilem-create #'evil-forward-arg)
"A" (evilem-create #'evil-backward-arg)
"s" (evilem-create #'evil-snipe-repeat
:name 'evil-easymotion-snipe-forward
:pre-hook (save-excursion (call-interactively #'evil-snipe-s))
:bind ((evil-snipe-scope 'buffer)
(evil-snipe-enable-highlight)
(evil-snipe-enable-incremental-highlight)))
"S" (evilem-create #'evil-snipe-repeat
:name 'evil-easymotion-snipe-backward
:pre-hook (save-excursion (call-interactively #'evil-snipe-S))
:bind ((evil-snipe-scope 'buffer)
(evil-snipe-enable-highlight)
(evil-snipe-enable-incremental-highlight)))
"SPC" (λ!! #'evil-avy-goto-char-timer t)
"/" #'evil-avy-goto-char-timer)
;; text object plugins
:textobj "x" #'evil-inner-xml-attr #'evil-outer-xml-attr
:textobj "a" #'evil-inner-arg #'evil-outer-arg
:textobj "B" #'evil-textobj-anyblock-inner-block #'evil-textobj-anyblock-a-block
:textobj "i" #'evil-indent-plus-i-indent #'evil-indent-plus-a-indent
:textobj "k" #'evil-indent-plus-i-indent-up #'evil-indent-plus-a-indent-up
:textobj "j" #'evil-indent-plus-i-indent-up-down #'evil-indent-plus-a-indent-up-down
;; evil-snipe
(:after evil-snipe
:map evil-snipe-parent-transient-map
"C-;" (λ! (require 'evil-easymotion)
(call-interactively
(evilem-create #'evil-snipe-repeat
:bind ((evil-snipe-scope 'whole-buffer)
(evil-snipe-enable-highlight)
(evil-snipe-enable-incremental-highlight))))))
;; evil-surround
:v "S" #'evil-surround-region
:o "s" #'evil-surround-edit
:o "S" #'evil-Surround-edit)
;;
;;; Module keybinds
;;; :completion
(map! (:when (featurep! :completion company)
:i "C-@" #'+company/complete
:i "C-SPC" #'+company/complete
(:prefix "C-x"
:i "C-l" #'+company/whole-lines
:i "C-k" #'+company/dict-or-keywords
:i "C-f" #'company-files
:i "C-]" #'company-etags
:i "s" #'company-ispell
:i "C-s" #'company-yasnippet
:i "C-o" #'company-capf
:i "C-n" #'+company/dabbrev
:i "C-p" #'+company/dabbrev-code-previous)
(:after company
(:map company-active-map
"C-w" nil ; don't interfere with `evil-delete-backward-word'
"C-n" #'company-select-next
"C-p" #'company-select-previous
"C-j" #'company-select-next
"C-k" #'company-select-previous
"C-h" #'company-show-doc-buffer
"C-u" #'company-previous-page
"C-d" #'company-next-page
"C-s" #'company-filter-candidates
"C-S-s" (cond ((featurep! :completion helm) #'helm-company)
((featurep! :completion ivy) #'counsel-company))
"C-SPC" #'company-complete-common
"TAB" #'company-complete-common-or-cycle
[tab] #'company-complete-common-or-cycle
[backtab] #'company-select-previous)
(:map company-search-map ; applies to `company-filter-map' too
"C-n" #'company-select-next-or-abort
"C-p" #'company-select-previous-or-abort
"C-j" #'company-select-next-or-abort
"C-k" #'company-select-previous-or-abort
"C-s" (λ! (company-search-abort) (company-filter-candidates))
"ESC" #'company-search-abort)
;; TAB auto-completion in term buffers
(:map comint-mode-map
"TAB" #'company-complete
[tab] #'company-complete)))
(:when (featurep! :completion ivy)
(:map (help-mode-map helpful-mode-map)
:n "Q" #'ivy-resume)
(:after ivy
:map ivy-minibuffer-map
"C-SPC" #'ivy-call-and-recenter ; preview file
"C-l" #'ivy-alt-done
"C-v" #'yank)
(:after counsel
:map counsel-ag-map
"C-SPC" #'ivy-call-and-recenter ; preview
"C-l" #'ivy-done
[C-return] (+ivy-do-action! #'+ivy-git-grep-other-window-action)))
(:when (featurep! :completion helm)
(:after helm
(:map helm-map
[left] #'left-char
[right] #'right-char
"C-S-n" #'helm-next-source
"C-S-p" #'helm-previous-source
"C-j" #'helm-next-line
"C-k" #'helm-previous-line
"C-S-j" #'helm-next-source
"C-S-k" #'helm-previous-source
"C-f" #'helm-next-page
"C-S-f" #'helm-previous-page
"C-u" #'helm-delete-minibuffer-contents
"C-w" #'backward-kill-word
"C-r" #'evil-paste-from-register ; Evil registers in helm! Glorious!
"C-s" #'helm-minibuffer-history
"C-b" #'backward-word
;; Swap TAB and C-z
"TAB" #'helm-execute-persistent-action
[tab] #'helm-execute-persistent-action
"C-z" #'helm-select-action)
(:after helm-ag
:map helm-ag-map
"C--" #'+helm-do-ag-decrease-context
"C-=" #'+helm-do-ag-increase-context
[left] nil
[right] nil)
(:after helm-files
:map (helm-find-files-map helm-read-file-map)
[C-return] #'helm-ff-run-switch-other-window
"C-w" #'helm-find-files-up-one-level)
(:after helm-locate
:map helm-generic-files-map
[C-return] #'helm-ff-run-switch-other-window)
(:after helm-buffers
:map helm-buffer-map
[C-return] #'helm-buffer-switch-other-window)
(:after helm-occur
:map helm-occur-map
[C-return] #'helm-occur-run-goto-line-ow)
(:after helm-grep
:map helm-grep-map
[C-return] #'helm-grep-run-other-window-action))))
;;; :ui
(map! (:when (featurep! :ui hl-todo)
:m "]t" #'hl-todo-next
:m "[t" #'hl-todo-previous)
(:when (featurep! :ui neotree)
:after neotree
:map neotree-mode-map
:n "g" nil
:n "TAB" #'neotree-quick-look
:n "RET" #'neotree-enter
:n [tab] #'neotree-quick-look
:n [return] #'neotree-enter
:n "DEL" #'evil-window-prev
:n "c" #'neotree-create-node
:n "r" #'neotree-rename-node
:n "d" #'neotree-delete-node
:n "j" #'neotree-next-line
:n "k" #'neotree-previous-line
:n "n" #'neotree-next-line
:n "p" #'neotree-previous-line
:n "h" #'+neotree/collapse-or-up
:n "l" #'+neotree/expand-or-open
:n "J" #'neotree-select-next-sibling-node
:n "K" #'neotree-select-previous-sibling-node
:n "H" #'neotree-select-up-node
:n "L" #'neotree-select-down-node
:n "G" #'evil-goto-line
:n "gg" #'evil-goto-first-line
:n "v" #'neotree-enter-vertical-split
:n "s" #'neotree-enter-horizontal-split
:n "q" #'neotree-hide
:n "R" #'neotree-refresh)
(:when (featurep! :ui popup)
:n "C-`" #'+popup/toggle
:n "C-~" #'+popup/raise
:g "C-x p" #'+popup/other)
(:when (featurep! :ui vc-gutter)
:m "]d" #'git-gutter:next-hunk
:m "[d" #'git-gutter:previous-hunk)
(:when (featurep! :ui workspaces)
:n "gt" #'+workspace/switch-right
:n "gT" #'+workspace/switch-left
:n "]w" #'+workspace/switch-right
:n "[w" #'+workspace/switch-left
:g "M-1" #'+workspace/switch-to-0
:g "M-2" #'+workspace/switch-to-1
:g "M-3" #'+workspace/switch-to-2
:g "M-4" #'+workspace/switch-to-3
:g "M-5" #'+workspace/switch-to-4
:g "M-6" #'+workspace/switch-to-5
:g "M-7" #'+workspace/switch-to-6
:g "M-8" #'+workspace/switch-to-7
:g "M-9" #'+workspace/switch-to-8
:g "M-0" #'+workspace/switch-to-final
:g "M-t" #'+workspace/new
:g "M-T" #'+workspace/display))
;;; :editor
(map! (:when (featurep! :editor fold)
:nv "C-SPC" #'+fold/toggle)
(:when (featurep! :editor format)
:n "gQ" #'+format:region)
(:when (featurep! :editor multiple-cursors)
;; evil-mc
(:prefix "gz"
:nv "d" #'evil-mc-make-and-goto-next-match
:nv "D" #'evil-mc-make-and-goto-prev-match
:nv "j" #'evil-mc-make-cursor-move-next-line
:nv "k" #'evil-mc-make-cursor-move-prev-line
:nv "m" #'evil-mc-make-all-cursors
:nv "n" #'evil-mc-make-and-goto-next-cursor
:nv "N" #'evil-mc-make-and-goto-last-cursor
:nv "p" #'evil-mc-make-and-goto-prev-cursor
:nv "P" #'evil-mc-make-and-goto-first-cursor
:nv "q" #'evil-mc-undo-all-cursors
:nv "t" #'+multiple-cursors/evil-mc-toggle-cursors
:nv "u" #'evil-mc-undo-last-added-cursor
:nv "z" #'+multiple-cursors/evil-mc-make-cursor-here)
(:after evil-mc
:map evil-mc-key-map
:nv "C-n" #'evil-mc-make-and-goto-next-cursor
:nv "C-N" #'evil-mc-make-and-goto-last-cursor
:nv "C-p" #'evil-mc-make-and-goto-prev-cursor
:nv "C-P" #'evil-mc-make-and-goto-first-cursor)
;; evil-multiedit
:v "R" #'evil-multiedit-match-all
:n "M-d" #'evil-multiedit-match-symbol-and-next
:n "M-D" #'evil-multiedit-match-symbol-and-prev
:v "M-d" #'evil-multiedit-match-and-next
:v "M-D" #'evil-multiedit-match-and-prev
:nv "C-M-d" #'evil-multiedit-restore
(:after evil-multiedit
(:map evil-multiedit-state-map
"M-d" #'evil-multiedit-match-and-next
"M-D" #'evil-multiedit-match-and-prev
"RET" #'evil-multiedit-toggle-or-restrict-region
[return] #'evil-multiedit-toggle-or-restrict-region)
(:map (evil-multiedit-state-map evil-multiedit-insert-state-map)
"C-n" #'evil-multiedit-next
"C-p" #'evil-multiedit-prev)))
(:when (featurep! :editor rotate-text)
:n "!" #'rotate-text)
(:when (featurep! :editor snippets)
;; auto-yasnippet
:i [C-tab] #'aya-expand
:nv [C-tab] #'aya-create
;; yasnippet
(:after yasnippet
(:map yas-keymap
"C-e" #'+snippets/goto-end-of-field
"C-a" #'+snippets/goto-start-of-field
[M-right] #'+snippets/goto-end-of-field
[M-left] #'+snippets/goto-start-of-field
[M-backspace] #'+snippets/delete-to-start-of-field
[backspace] #'+snippets/delete-backward-char
[delete] #'+snippets/delete-forward-char-or-field))))
;;; :emacs
(map! (:when (featurep! :emacs vc)
:after git-timemachine
:map git-timemachine-mode-map
:n "C-p" #'git-timemachine-show-previous-revision
:n "C-n" #'git-timemachine-show-next-revision
:n "[[" #'git-timemachine-show-previous-revision
:n "]]" #'git-timemachine-show-next-revision
:n "q" #'git-timemachine-quit
:n "gb" #'git-timemachine-blame))
;;; :tools
(map! (:when (featurep! :tools eval)
:g "M-r" #'+eval/buffer
:nv "gr" #'+eval:region
:n "gR" #'+eval/buffer
:v "gR" #'+eval:replace-region)
(:when (featurep! :tools flyspell)
;; Keybinds that have no Emacs+evil analogues (i.e. don't exist):
;; zq - mark word at point as good word
;; zw - mark word at point as bad
;; zu{q,w} - undo last marking
;; Keybinds that evil define:
;; z= - correct flyspell word at point
;; ]s - jump to previous spelling error
;; [s - jump to next spelling error
(:map flyspell-mouse-map
"RET" #'flyspell-correct-word-generic
[return] #'flyspell-correct-word-generic
[mouse-1] #'flyspell-correct-word-generic))
(:when (featurep! :tools flycheck)
(:after flycheck
:map flycheck-error-list-mode-map
:n "C-n" #'flycheck-error-list-next-error
:n "C-p" #'flycheck-error-list-previous-error
:n "j" #'flycheck-error-list-next-error
:n "k" #'flycheck-error-list-previous-error
:n "RET" #'flycheck-error-list-goto-error
:n [return] #'flycheck-error-list-goto-error))
(:when (featurep! :tools gist)
:after gist
:map gist-list-menu-mode-map
:n "go" #'gist-browse-current-url
:n "gr" #'gist-list-reload
:n "c" #'gist-add-buffer
:n "d" #'gist-kill-current
:n "e" #'gist-edit-current-description
:n "f" #'gist-fork
:n "q" #'kill-current-buffer
:n "s" #'gist-star
:n "S" #'gist-unstar
:n "y" #'gist-print-current-url)
(:when (featurep! :tools lookup)
:nv "K" #'+lookup/documentation
:nv "gd" #'+lookup/definition
:nv "gD" #'+lookup/references
:nv "gf" #'+lookup/file)
(:when (featurep! :tools magit)
(:after evil-magit
;; fix conflicts with private bindings
:map (magit-status-mode-map magit-revision-mode-map)
"C-j" nil
"C-k" nil)
(:map transient-map
"q" #'transient-quit-one)))
;;; :lang
(map! (:when (featurep! :lang markdown)
:after markdown-mode
:map markdown-mode-map
;; fix conflicts with private bindings
[backspace] nil))
;;
;;; <leader>
(map! :leader
:desc "Eval expression" ";" #'eval-expression
:desc "M-x" ":" #'execute-extended-command
:desc "Pop up scratch buffer" "x" #'doom/open-scratch-buffer
:desc "Org Capture" "X" #'org-capture
;; C-u is used by evil
:desc "Universal argument" "u" #'universal-argument
:desc "window" "w" evil-window-map
:desc "help" "h" help-map
:desc "Toggle last popup" "~" #'+popup/toggle
:desc "Find file" "." #'find-file
:desc "Switch buffer" "," #'switch-to-buffer
(:when (featurep! :ui workspaces)
:desc "Switch workspace buffer" "," #'persp-switch-to-buffer
:desc "Switch buffer" "<" #'switch-to-buffer)
:desc "Resume last search" "'"
(cond ((featurep! :completion ivy) #'ivy-resume)
((featurep! :completion helm) #'helm-resume))
:desc "Search for symbol in project" "*" #'+default/search-project-for-symbol-at-point
:desc "Find file in project" "SPC" #'projectile-find-file
:desc "Blink cursor line" "DEL" #'+nav-flash/blink-cursor
:desc "Jump to bookmark" "RET" #'bookmark-jump
;;; <leader> / --- search
(:prefix-map ("/" . "search")
:desc "Search buffer" "b" #'swiper
:desc "Search current directory" "d" #'+default/search-cwd
:desc "Search other directory" "D" #'+default/search-other-cwd
:desc "Jump to symbol" "i" #'imenu
:desc "Jump to link" "l" #'ace-link
:desc "Look up online" "o" #'+lookup/online
:desc "Look up online (w/ prompt)" "O" #'+lookup/online-select
:desc "Look up in local docsets" "k" #'+lookup/in-docsets
:desc "Look up in all docsets" "K" #'+lookup/in-all-docsets
:desc "Search project" "p" #'+default/search-project
:desc "Search other project" "P" #'+default/search-other-project)
;;; <leader> TAB --- workspace
(:when (featurep! :ui workspaces)
(:prefix-map ("TAB" . "workspace")
:desc "Display tab bar" "TAB" #'+workspace/display
:desc "Switch workspace" "." #'+workspace/switch-to
:desc "Switch to last workspace" "`" #'+workspace/other
:desc "New workspace" "n" #'+workspace/new
:desc "Load workspace from file" "l" #'+workspace/load
:desc "Save workspace to file" "s" #'+workspace/save
:desc "Delete session" "x" #'+workspace/kill-session
:desc "Delete this workspace" "d" #'+workspace/delete
:desc "Rename workspace" "r" #'+workspace/rename
:desc "Restore last session" "R" #'+workspace/restore-last-session
:desc "Next workspace" "]" #'+workspace/switch-right
:desc "Previous workspace" "[" #'+workspace/switch-left
:desc "Switch to 1st workspace" "1" #'+workspace/switch-to-0
:desc "Switch to 2nd workspace" "2" #'+workspace/switch-to-1
:desc "Switch to 3rd workspace" "3" #'+workspace/switch-to-2
:desc "Switch to 4th workspace" "4" #'+workspace/switch-to-3
:desc "Switch to 5th workspace" "5" #'+workspace/switch-to-4
:desc "Switch to 6th workspace" "6" #'+workspace/switch-to-5
:desc "Switch to 7th workspace" "7" #'+workspace/switch-to-6
:desc "Switch to 8th workspace" "8" #'+workspace/switch-to-7
:desc "Switch to 9th workspace" "9" #'+workspace/switch-to-8
:desc "Switch to final workspace" "0" #'+workspace/switch-to-final))
;;; <leader> b --- buffer
(:prefix-map ("b" . "buffer")
:desc "Toggle narrowing" "-" #'doom/clone-and-narrow-buffer
:desc "Previous buffer" "[" #'previous-buffer
:desc "Next buffer" "]" #'next-buffer
(:when (featurep! :ui workspaces)
:desc "Switch workspace buffer" "b" #'persp-switch-to-buffer
:desc "Switch buffer" "B" #'switch-to-buffer)
(:unless (featurep! :ui workspaces)
:desc "Switch buffer" "b" #'switch-to-buffer)
:desc "Kill buffer" "k" #'kill-current-buffer
:desc "Next buffer" "n" #'next-buffer
:desc "New empty buffer" "N" #'evil-buffer-new
:desc "Kill other buffers" "o" #'doom/kill-other-buffers
:desc "Previous buffer" "p" #'previous-buffer
:desc "Save buffer" "s" #'save-buffer
:desc "Sudo edit this file" "S" #'doom/sudo-this-file
:desc "Pop up scratch buffer" "x" #'doom/open-scratch-buffer
:desc "Switch to scratch buffer" "X" #'doom/switch-to-scratch-buffer
:desc "Bury buffer" "z" #'bury-buffer)
;;; <leader> c --- code
(:prefix-map ("c" . "code")
:desc "Compile" "c" #'compile
:desc "Jump to definition" "d" #'+lookup/definition
:desc "Jump to references" "D" #'+lookup/references
:desc "Evaluate buffer/region" "e" #'+eval/buffer-or-region
:desc "Evaluate & replace region" "E" #'+eval:replace-region
:desc "Format buffer/region" "f" #'+format/region-or-buffer
:desc "Jump to documentation" "k" #'+lookup/documentation
:desc "Open REPL" "r" #'+eval/open-repl-other-window
:desc "Delete trailing whitespace" "w" #'delete-trailing-whitespace
:desc "Delete trailing newlines" "W" #'doom/delete-trailing-newlines
:desc "List errors" "x" #'flycheck-list-errors)
;;; <leader> f --- file
(:prefix-map ("f" . "file")
:desc "Find file" "." #'find-file
:desc "Find file from here" "/"
(if (featurep! :completion ivy)
#'counsel-file-jump
(λ! (doom-project-find-file default-directory)))
:desc "Open project editorconfig" "c" #'editorconfig-find-current-editorconfig
:desc "Find directory" "d" #'dired
:desc "Find file in emacs.d" "e" #'+default/find-in-emacsd
:desc "Browse emacs.d" "E" #'+default/browse-emacsd
:desc "Find file from here" "f" #'find-file
:desc "Move/rename file" "m" #'doom/move-this-file
:desc "Find file in private config" "p" #'doom/find-file-in-private-config
:desc "Browse private config" "P" #'doom/open-private-config
:desc "Recent files" "r" #'recentf-open-files
:desc "Recent project files" "R" #'projectile-recentf
:desc "Save file" "s" #'save-buffer
:desc "Sudo find file" "S" #'doom/sudo-find-file
:desc "Delete this file" "X" #'doom/delete-this-file
:desc "Yank filename" "y" #'+default/yank-buffer-filename)
;;; <leader> g --- git
(:prefix-map ("g" . "git")
:desc "Git revert file" "R" #'vc-revert
(:when (featurep! :ui vc-gutter)
:desc "Git revert hunk" "r" #'git-gutter:revert-hunk
:desc "Git stage hunk" "s" #'git-gutter:stage-hunk
:desc "Git time machine" "t" #'git-timemachine-toggle
:desc "Jump to next hunk" "]" #'git-gutter:next-hunk
:desc "Jump to previous hunk" "[" #'git-gutter:previous-hunk)
(:when (featurep! :tools magit)
:desc "Magit dispatch" "/" #'magit-dispatch
:desc "Forge dispatch" "'" #'forge-dispatch
:desc "Magit switch branch" "b" #'magit-branch-checkout
:desc "Magit status" "g" #'magit-status
:desc "Magit file delete" "x" #'magit-file-delete
:desc "Magit blame" "B" #'magit-blame-addition
:desc "Magit clone" "C" #'+magit/clone
:desc "Magit fetch" "F" #'magit-fetch
:desc "Magit buffer log" "L" #'magit-log
:desc "Git stage file" "S" #'magit-stage-file
:desc "Git unstage file" "U" #'magit-unstage-file
(:prefix ("f" . "find")
:desc "Find file" "f" #'magit-find-file
:desc "Find gitconfig file" "g" #'magit-find-git-config-file
:desc "Find commit" "c" #'magit-show-commit
:desc "Find issue" "i" #'forge-visit-issue
:desc "Find pull request" "p" #'forge-visit-pullreq)
(:prefix ("o" . "open in browser")
:desc "Browse region or line" "." #'+vc/git-browse-region-or-line
:desc "Browse remote" "r" #'forge-browse-remote
:desc "Browse commit" "c" #'forge-browse-commit
:desc "Browse an issue" "i" #'forge-browse-issue
:desc "Browse a pull request" "p" #'forge-browse-pullreq
:desc "Browse issues" "I" #'forge-browse-issues
:desc "Browse pull requests" "P" #'forge-browse-pullreqs)
(:prefix ("l" . "list")
(:when (featurep! :tools gist)
:desc "List gists" "g" #'+gist:list)
:desc "List repositories" "r" #'magit-list-repositories
:desc "List submodules" "s" #'magit-list-submodules
:desc "List issues" "i" #'forge-list-issues
:desc "List pull requests" "p" #'forge-list-pullreqs
:desc "List notifications" "n" #'forge-list-notifications)
(:prefix ("c" . "create")
:desc "Initialize repo" "r" #'magit-init
:desc "Clone repo" "R" #'+magit/clone
:desc "Commit" "c" #'magit-commit-create
:desc "Branch" "b" #'magit-branch-and-checkout
:desc "Issue" "i" #'forge-create-issue
:desc "Pull request" "p" #'forge-create-pullreq)))
;;; <leader> i --- insert
(:prefix-map ("i" . "insert")
:desc "Insert from clipboard" "y" #'+default/yank-pop
:desc "Insert from evil register" "r" #'evil-ex-registers
:desc "Insert snippet" "s" #'yas-insert-snippet)
;;; <leader> n --- notes
(:prefix-map ("n" . "notes")
:desc "Browse notes" "." #'+default/browse-notes
:desc "Search notes" "/" #'+default/org-notes-search
:desc "Search notes for symbol" "*" #'+default/search-notes-for-symbol-at-point
:desc "Org capture" "c" #'org-capture
:desc "Open deft" "d" #'deft
:desc "Search org agenda headlines" "h" #'+default/org-notes-headlines
:desc "Find file in notes" "n" #'+default/find-in-notes
:desc "Browse notes" "N" #'+default/browse-notes
:desc "Org store link" "l" #'org-store-link)
;;; <leader> o --- open
(:prefix-map ("o" . "open")
:desc "Org agenda" "A" #'org-agenda
(:prefix ("a" . "org agenda")
:desc "Agenda" "a" #'org-agenda
:desc "Todo list" "t" #'org-todo-list
:desc "Tags search" "m" #'org-tags-view
:desc "View search" "v" #'org-search-view)
:desc "Default browser" "b" #'browse-url-of-file
:desc "Start debugger" "d" #'+debugger/start
:desc "REPL" "r" #'+eval/open-repl-other-window
:desc "REPL (same window)" "R" #'+eval/open-repl-same-window
:desc "Dired" "-" #'dired-jump
(:when (featurep! :ui neotree)
:desc "Project sidebar" "p" #'+neotree/open
:desc "Find file in project sidebar" "P" #'+neotree/find-this-file)
(:when (featurep! :ui treemacs)
:desc "Project sidebar" "p" #'+treemacs/toggle
:desc "Find file in project sidebar" "P" #'+treemacs/find-file)
(:when (featurep! :term shell)
:desc "Toggle shell popup" "t" #'+shell/toggle
:desc "Open shell here" "T" #'+shell/here)
(:when (featurep! :term term)
:desc "Toggle terminal popup" "t" #'+term/toggle
:desc "Open terminal here" "T" #'+term/here)
(:when (featurep! :term vterm)
:desc "Toggle vterm popup" "t" #'+vterm/toggle
:desc "Open vterm here" "T" #'+vterm/here)
(:when (featurep! :term eshell)
:desc "Toggle eshell popup" "e" #'+eshell/toggle
:desc "Open eshell here" "E" #'+eshell/here)
(:when (featurep! :collab floobits)
(:prefix ("f" . "floobits")
"c" #'floobits-clear-highlights
"f" #'floobits-follow-user
"j" #'floobits-join-workspace
"l" #'floobits-leave-workspace
"R" #'floobits-share-dir-private
"s" #'floobits-summon
"t" #'floobits-follow-mode-toggle
"U" #'floobits-share-dir-public))
(:when (featurep! :tools macos)
:desc "Reveal in Finder" "o" #'+macos/reveal-in-finder
:desc "Reveal project in Finder" "O" #'+macos/reveal-project-in-finder
:desc "Send to Transmit" "u" #'+macos/send-to-transmit
:desc "Send project to Transmit" "U" #'+macos/send-project-to-transmit
:desc "Send to Launchbar" "l" #'+macos/send-to-launchbar
:desc "Send project to Launchbar" "L" #'+macos/send-project-to-launchbar)
(:when (featurep! :tools docker)
:desc "Docker" "D" #'docker))
;;; <leader> p --- project
(:prefix-map ("p" . "project")
:desc "Browse project" "." #'+default/browse-project
:desc "Browse other project" ">" #'doom/browse-in-other-project
:desc "Find file in project" "/" #'projectile-find-file
:desc "Find file in other project" "?" #'doom/find-file-in-other-project
:desc "Run cmd in project root" "!" #'projectile-run-shell-command-in-root
:desc "Add new project" "a" #'projectile-add-known-project
:desc "Switch to project buffer" "b" #'projectile-switch-to-buffer
:desc "Compile in project" "c" #'projectile-compile-project
:desc "Configure project" "C" #'projectile-configure-project
:desc "Remove known project" "d" #'projectile-remove-known-project
:desc "Edit project .dir-locals" "e" #'projectile-edit-dir-locals
:desc "Invalidate project cache" "i" #'projectile-invalidate-cache
:desc "Kill project buffers" "k" #'projectile-kill-buffers
:desc "Repeat last external command" "l" #'projectile-repeat-last-command
:desc "Find other file" "o" #'projectile-find-other-file
:desc "Switch project" "p" #'projectile-switch-project
:desc "Find recent project files" "r" #'projectile-recentf
:desc "Run project" "R" #'projectile-run-project
:desc "Pop up scratch buffer" "x" #'doom/open-project-scratch-buffer
:desc "Switch to scratch buffer" "X" #'doom/switch-to-project-scratch-buffer
:desc "List project tasks" "t" #'+default/project-tasks
:desc "Test project" "T" #'projectile-test-project)
;;; <leader> q --- session
(:prefix-map ("q" . "session")
:desc "Quit Emacs" "q" #'save-buffers-kill-terminal
:desc "Quit Emacs without saving" "Q" #'evil-quit-all-with-error-code
:desc "Quick save current session" "s" #'doom/quicksave-session
:desc "Restore last session" "l" #'doom/quickload-session
:desc "Save session to file" "S" #'doom/save-session
:desc "Restore session from file" "L" #'doom/load-session
:desc "Restart & restore Emacs" "r" #'doom/restart-and-restore
:desc "Restart Emacs" "R" #'doom/restart)
;;; <leader> r --- remote
(:when (featurep! :tools upload)
(:prefix-map ("r" . "remote")
:desc "Upload local" "u" #'ssh-deploy-upload-handler
:desc "Upload local (force)" "U" #'ssh-deploy-upload-handler-forced
:desc "Download remote" "d" #'ssh-deploy-download-handler
:desc "Diff local & remote" "D" #'ssh-deploy-diff-handler
:desc "Browse remote files" "." #'ssh-deploy-browse-remote-handler
:desc "Detect remote changes" ">" #'ssh-deploy-remote-changes-handler))
;;; <leader> s --- snippets
(:when (featurep! :editor snippets)
(:prefix-map ("s" . "snippets")
:desc "View snippet for mode" "/" #'+snippets/find-for-current-mode
:desc "View snippet (global)" "?" #'+snippets/find
:desc "Edit snippet" "c" #'+snippet/edit
:desc "View private snippet" "f" #'+snippets/find-private
:desc "Insert snippet" "i" #'yas-insert-snippet
:desc "New snippet" "n" #'+snippet/new
:desc "New snippet alias" "N" #'+snippet/new-alias
:desc "Reload snippets" "r" #'yas-reload-all
:desc "Create temporary snippet" "s" #'aya-create
:desc "Expand temporary snippet" "e" #'aya-expand))
;;; <leader> t --- toggle
(:prefix-map ("t" . "toggle")
:desc "Big mode" "b" #'doom-big-font-mode
:desc "Flycheck" "f" #'flycheck-mode
:desc "Frame fullscreen" "F" #'toggle-frame-fullscreen
:desc "Evil goggles" "g" #'evil-goggles-mode
:desc "Impatient mode" "h" #'+impatient-mode/toggle
:desc "Indent guides" "i" #'highlight-indent-guides-mode
:desc "Indent style" "I" #'doom/toggle-indent-style
:desc "Line numbers" "l" #'doom/toggle-line-numbers
:desc "Word-wrap mode" "w" #'+word-wrap-mode
:desc "org-tree-slide mode" "p" #'+org-present/start
:desc "Flyspell" "s" #'flyspell-mode))
;;
;;; Universal motion repeating keys
(defvar +default-repeat-keys (cons ";" ",")
"The keys to use for repeating motions.
This is a cons cell whose CAR is the key for repeating a motion forward, and
whose CDR is for repeating backward. They should both be kbd-able strings.")
(when +default-repeat-keys
(defmacro set-repeater! (command next-func prev-func)
"Makes ; and , the universal repeat-keys in evil-mode.
To change these keys see `+default-repeat-keys'."
(let ((fn-sym (intern (format "+default/repeat-%s" (doom-unquote command)))))
`(progn
(defun ,fn-sym (&rest _)
(evil-define-key* 'motion 'local
(kbd (car +default-repeat-keys)) #',next-func
(kbd (cdr +default-repeat-keys)) #',prev-func))
(advice-add #',command :after-while #',fn-sym))))
;; n/N
(set-repeater! evil-ex-search-next evil-ex-search-next evil-ex-search-previous)
(set-repeater! evil-ex-search-previous evil-ex-search-next evil-ex-search-previous)
(set-repeater! evil-ex-search-forward evil-ex-search-next evil-ex-search-previous)
(set-repeater! evil-ex-search-backward evil-ex-search-next evil-ex-search-previous)
;; f/F/t/T/s/S
(after! evil-snipe
(setq evil-snipe-repeat-keys nil
evil-snipe-override-evil-repeat-keys nil) ; causes problems with remapped ;
(set-repeater! evil-snipe-f evil-snipe-repeat evil-snipe-repeat-reverse)
(set-repeater! evil-snipe-F evil-snipe-repeat evil-snipe-repeat-reverse)
(set-repeater! evil-snipe-t evil-snipe-repeat evil-snipe-repeat-reverse)
(set-repeater! evil-snipe-T evil-snipe-repeat evil-snipe-repeat-reverse)
(set-repeater! evil-snipe-s evil-snipe-repeat evil-snipe-repeat-reverse)
(set-repeater! evil-snipe-S evil-snipe-repeat evil-snipe-repeat-reverse)
(set-repeater! evil-snipe-x evil-snipe-repeat evil-snipe-repeat-reverse)
(set-repeater! evil-snipe-X evil-snipe-repeat evil-snipe-repeat-reverse))
;; */#
(set-repeater! evil-visualstar/begin-search-forward
evil-ex-search-next evil-ex-search-previous)
(set-repeater! evil-visualstar/begin-search-backward
evil-ex-search-previous evil-ex-search-next))
;;
;;; Universal evil integration
(when (featurep! :editor evil +everywhere)
;; Have C-u behave similarly to `doom/backward-to-bol-or-indent'.
;; NOTE SPC u replaces C-u as the universal argument.
(map! :gi "C-u" #'doom/backward-kill-to-bol-and-indent
:gi "C-w" #'backward-kill-word
;; Vimmish ex motion keys
:gi "C-b" #'backward-word
:gi "C-f" #'forward-word)
(after! view
(define-key view-mode-map [escape] #'View-quit-all))
(after! man
(evil-define-key* 'normal Man-mode-map "q" #'kill-current-buffer))
;; Minibuffer
(define-key! evil-ex-completion-map
"C-a" #'move-beginning-of-line
"C-b" #'backward-word
"C-s" (if (featurep! :completion ivy)
#'counsel-minibuffer-history
#'helm-minibuffer-history))
(define-key! :keymaps +default-minibuffer-maps
[escape] #'abort-recursive-edit
"C-v" #'yank
"C-z" (λ! (ignore-errors (call-interactively #'undo)))
"C-a" #'move-beginning-of-line
"C-b" #'backward-word
"C-r" #'evil-paste-from-register
;; Scrolling lines
"C-j" #'next-line
"C-k" #'previous-line
"C-S-j" #'scroll-up-command
"C-S-k" #'scroll-down-command)
(define-key! read-expression-map
"C-j" #'next-line-or-history-element
"C-k" #'previous-line-or-history-element))