Evil Mode

about | blog | config | notes | github

1. Extensible Vi Layer for Emacs

evil_mode_logo.png

A pretty nice package that is used for lets you use the primary features of vim keybindings from wtihin GNU/Emacs. The configuration below will contain any packages that have to do with setting up evil properly.

2. Configuration

2.1. Enable Evil

github:emacs-evil/evil is the core of Evil-Mode. This basicallly adds the modal functionality to emacs that we see in vim. But we also add a little bit of our own custom bindings not set by default that were present in vim for the sake of my sanity.

(use-package evil
  :init
  (setq evil-want-keybinding nil)
  :config
  (evil-mode 1)
  (define-key evil-insert-state-map (kbd "C-g") 'evil-normal-state)

  ;; The defaults for Shift-j/k are not inuitive. I even remapped them
  ;; back when I was using vim as well becuase I would accidentally
  ;; press it all the time.
  (define-key evil-normal-state-map (kbd "J") nil)
  (define-key evil-normal-state-map (kbd "K") nil)

  ;; We want to override the RET key for other useful things but
  ;; Evil takes control of it because its evil. The same is true
  ;; for SPC and TAB but I'm not sure if I want those yet.
  (define-key evil-motion-state-map (kbd "RET") nil)
  ;(define-key evil-motion-state-map (kbd "SPC") nil)
  ;(define-key evil-motion-state-map (kbd "TAB") nil)

  ;; Use visual line motions even outside of visual-line-mode buffers
  (evil-global-set-key 'motion "j" 'evil-next-visual-line)
  (evil-global-set-key 'motion "k" 'evil-previous-visual-line)

  ;; configure initial states in specific modes
  (evil-set-initial-state 'messages-buffer-mode 'normal)
  (evil-set-initial-state 'dashboard-mode 'normal))

2.2. Setup Undo-Tree

evil-mode is nice, but the undo system could be improved alot if we make use of Undo Tree so let's ensure that's setup first.

(require 'init-undo-tree)

We also need to tell evil-mode to actually use it once its loaded.

(evil-set-undo-system 'undo-tree)

2.3. Extra Collections

github:emacs-evil/evil-collection adds support for vi-like bindings in modes that the core evil-mode package doesn't provide. There are quite a bit of packages here in this list so make sure to review it.

(use-package evil-collection
  :after evil
  :config
  (evil-collection-init)
  (evil-collection-define-key 'normal 'dired-mode-map
    "h" 'dired-single-up-directory
    "l" 'dired-single-buffer))

2.4. Quick Commenting

github:linktohack/evil-commentary adds keybindings for quick commenting. Use gcc to comment out a line, use gcap to comment out a paragraph, use gc in visual mode to comment out a selection.

(use-package evil-commentary
  :after evil
  :diminish
  :config (evil-commentary-mode +1))

2.5. Display Marks in Fringe

github:Andrew-William-Smith/evil-fringe-mark lets us change the right fringe of the buffer is used to show visual hints for markers that we mark with m. These marks can be jumped to with '.

(use-package evil-fringe-mark
  :disabled
  :after evil
  :custom
  ;; (right-fringe-width 16)
  (evil-fringe-mark-side 'right-fringe)
  (evil-fringe-mark-show-special t)
  :config
  (global-evil-fringe-mark-mode))

2.6. Package Provides

(provide 'init-evil)

Created: 2021-11-13

Emacs 26.1 (Org mode 9.5)