forked from SystemCrafters/crafted-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rational-evil.el
80 lines (60 loc) · 2.84 KB
/
rational-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
;;; rational-evil.el -*- lexical-binding: t; -*-
;; Copyright (C) 2022
;; SPDX-License-Identifier: MIT
;; Author: System Crafters Community
;; Commentary
;; Evil mode configuration, for those who prefer `vi' keybindings.
;;; Code:
;; Define configuration variables
(defcustom rational-evil-discourage-arrow-keys nil
"When t, prevent the use of arrow keys in normal state to
encourage the use of Vim-style movement keys (hjkl).")
;; Install dependencies
(rational-package-install-package 'evil)
(rational-package-install-package 'undo-tree)
(rational-package-install-package 'evil-collection)
(rational-package-install-package 'evil-nerd-commenter)
;; Turn on undo-tree globally
(global-undo-tree-mode)
;; Set some variables that must be configured before loading the package
(customize-set-variable 'evil-want-integration t)
(customize-set-variable 'evil-want-keybinding nil)
(customize-set-variable 'evil-want-C-i-jump nil)
(customize-set-variable 'evil-respect-visual-line-mode t)
(customize-set-variable 'evil-undo-system 'undo-tree)
;; Load Evil and enable it globally
(require 'evil)
(evil-mode 1)
;; Turn on Evil Nerd Commenter
(evilnc-default-hotkeys)
;; Make C-g revert to normal state
(define-key evil-insert-state-map (kbd "C-g") 'evil-normal-state)
;; Rebind `universal-argument' to 'C-M-u' since 'C-u' now scrolls the buffer
(global-set-key (kbd "C-M-u") 'universal-argument)
;; C-h is backspace in insert state
(define-key evil-insert-state-map (kbd "C-h") 'evil-delete-backward-char-and-join)
;; 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)
(defun rational-evil/discourage-arrow-keys ()
(interactive)
(message "Use HJKL keys instead!"))
(when rational-evil-discourage-arrow-keys
;; Disable arrow keys in normal and visual modes
(define-key evil-normal-state-map (kbd "<left>") 'rational-evil/discourage-arrow-keys)
(define-key evil-normal-state-map (kbd "<right>") 'rational-evil/discourage-arrow-keys)
(define-key evil-normal-state-map (kbd "<down>") 'rational-evil/discourage-arrow-keys)
(define-key evil-normal-state-map (kbd "<up>") 'rational-evil/discourage-arrow-keys)
(evil-global-set-key 'motion (kbd "<left>") 'rational-evil/discourage-arrow-keys)
(evil-global-set-key 'motion (kbd "<right>") 'rational-evil/discourage-arrow-keys)
(evil-global-set-key 'motion (kbd "<down>") 'rational-evil/discourage-arrow-keys)
(evil-global-set-key 'motion (kbd "<up>") 'rational-evil/discourage-arrow-keys))
;; Make sure some modes start in Emacs state
;; TODO: Split this out to other configuration modules?
(dolist (mode '(custom-mode
eshell-mode
term-mode))
(add-to-list 'evil-emacs-state-modes mode))
(evil-collection-init)
(provide 'rational-evil)
;;; rational-evil.el ends here