summaryrefslogtreecommitdiff
path: root/dot_config/emacs/lisp/evil-config.el
blob: 0be0cc6e0bf0dc850ca247986ec2ccdd513bd114 (plain)
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
;; EVIL
;; The `evil' package provides Vim emulation within Emacs, allowing
;; users to edit text in a modal way, similar to how Vim
;; operates. This setup configures `evil-mode' to enhance the editing
;; experience.
(use-package evil
  :straight t
  :ensure t
  :defer t
  :hook
  (after-init . evil-mode)
  :init
  (setq evil-want-integration t)      ;; Integrate `evil' with other Emacs features (optional as it's true by default).
  (setq evil-want-keybinding nil)     ;; Disable default keybinding to set custom ones.
  (setq evil-want-C-u-scroll t)       ;; Makes C-u scroll
  (setq evil-want-C-u-delete t)       ;; Makes C-u delete on insert mode
  :config
  (setq evil-want-fine-undo t)        ;; Evil uses finer grain undoing steps

  ;; Keybindings for searching and finding files.
  (evil-define-key 'normal 'global (kbd "C-c s f") 'consult-find)
  (evil-define-key 'normal 'global (kbd "C-c s g") 'consult-grep)
  (evil-define-key 'normal 'global (kbd "C-c s G") 'consult-git-grep)
  (evil-define-key 'normal 'global (kbd "C-c s r") 'consult-ripgrep)
  (evil-define-key 'normal 'global (kbd "C-c s h") 'consult-info)
  (evil-define-key 'normal 'global (kbd "C-c /") 'consult-line)

  ;; Flymake navigation
  (evil-define-key 'normal 'global (kbd "C-c x x") 'consult-flymake);; Gives you something like `trouble.nvim'
  (evil-define-key 'normal 'global (kbd "] d") 'flymake-goto-next-error) ;; Go to next Flymake error
  (evil-define-key 'normal 'global (kbd "[ d") 'flymake-goto-prev-error) ;; Go to previous Flymake error

  ;; Diff-HL navigation for version control
  (evil-define-key 'normal 'global (kbd "] c") 'diff-hl-next-hunk) ;; Next diff hunk
  (evil-define-key 'normal 'global (kbd "[ c") 'diff-hl-previous-hunk) ;; Previous diff hunk

  ;; Magit keybindings for Git integration
  (evil-define-key 'normal 'global (kbd "C-c g g") 'magit-status)      ;; Open Magit status
  (evil-define-key 'normal 'global (kbd "C-c g l") 'magit-log-current) ;; Show current log
  (evil-define-key 'normal 'global (kbd "C-c g d") 'magit-diff-buffer-file) ;; Show diff for the current file
  (evil-define-key 'normal 'global (kbd "C-c g D") 'diff-hl-show-hunk) ;; Show diff for a hunk
  (evil-define-key 'normal 'global (kbd "C-c g b") 'vc-annotate)       ;; Annotate buffer with version control info

  ;; Buffer management keybindings
  (evil-define-key 'normal 'global (kbd "] b") 'switch-to-next-buffer) ;; Switch to next buffer
  (evil-define-key 'normal 'global (kbd "[ b") 'switch-to-prev-buffer) ;; Switch to previous buffer
  (evil-define-key 'normal 'global (kbd "C-c b i") 'consult-buffer) ;; Open consult buffer list
  (evil-define-key 'normal 'global (kbd "C-c b b") 'ibuffer) ;; Open Ibuffer
  (evil-define-key 'normal 'global (kbd "C-c SPC") 'consult-buffer) ;; Consult buffer

  ;; Yank from kill ring
  (evil-define-key 'normal 'global (kbd "P") 'consult-yank-from-kill-ring)
  (evil-define-key 'normal 'global (kbd "C-c P") 'consult-yank-from-kill-ring)

  ;; Tab navigation
  (evil-define-key 'normal 'global (kbd "] t") 'tab-next) ;; Go to next tab
  (evil-define-key 'normal 'global (kbd "[ t") 'tab-previous) ;; Go to previous tab

  ;; LSP commands keybindings
  (evil-define-key 'normal lsp-mode-map
                   ;; (kbd "gd") 'lsp-find-definition                ;; evil-collection already provides gd
                   (kbd "gr") 'lsp-find-references                   ;; Finds LSP references
                   (kbd "C-c c a") 'lsp-execute-code-action     ;; Execute code actions
                   (kbd "C-c r n") 'lsp-rename                  ;; Rename symbol
                   (kbd "gI") 'lsp-find-implementation               ;; Find implementation
                   (kbd "C-c l f") 'lsp-format-buffer)          ;; Format buffer via lsp

  (evil-define-key 'normal 'global (kbd "K")
        #'eldoc-box-help-at-point)

  ;; Enable evil mode
  (evil-mode 1))


;; EVIL COLLECTION
;; The `evil-collection' package enhances the integration of
;; `evil-mode' with various built-in and third-party packages. It
;; provides a better modal experience by remapping keybindings and
;; commands to fit the `evil' style.
(use-package evil-collection
  :straight t
  :defer t
  :ensure t
  :custom
  (evil-collection-want-find-usages-bindings t)
  ;; Hook to initialize `evil-collection' when `evil-mode' is activated.
  ;; :hook
  ;; (evil-mode . evil-collection-init))
  )

;; EVIL SURROUND
;; The `evil-surround' package provides text object surround
;; functionality for `evil-mode'. This allows for easily adding,
;; changing, or deleting surrounding characters such as parentheses,
;; quotes, and more.
;;
;; With this you can change 'hello there' with ci'" to have
;; "hello there" and cs"<p> to get <p>hello there</p>.
;; More examples here:
;; - https://github.com/emacs-evil/evil-surround?tab=readme-ov-file#examples
(use-package evil-surround
  :straight t
  :ensure t
  :after evil-collection
  :config
  (global-evil-surround-mode 1))

;; EVIL MATCHIT
;; The `evil-matchit' package extends `evil-mode' by enabling
;; text object matching for structures such as parentheses, HTML
;; tags, and other paired delimiters. This makes it easier to
;; navigate and manipulate code blocks.
;; Just use % for jumping between matching structures to check it out.
(use-package evil-matchit
  :ensure t
  :after evil-collection
  :config
  (global-evil-matchit-mode 1))

(use-package evil-keypad
  :straight t
  :ensure t
  :after evil
  :config
  (evil-keypad-global-mode 1))

(use-package evil-goggles
  :ensure t
  :config
  (evil-goggles-mode))

(provide 'evil-config)