summaryrefslogtreecommitdiff
path: root/dot_config/emacs/lisp/evil-config.el
diff options
context:
space:
mode:
Diffstat (limited to 'dot_config/emacs/lisp/evil-config.el')
-rw-r--r--dot_config/emacs/lisp/evil-config.el132
1 files changed, 132 insertions, 0 deletions
diff --git a/dot_config/emacs/lisp/evil-config.el b/dot_config/emacs/lisp/evil-config.el
new file mode 100644
index 0000000..0be0cc6
--- /dev/null
+++ b/dot_config/emacs/lisp/evil-config.el
@@ -0,0 +1,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)