This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-evil.el
196 lines (163 loc) · 6.53 KB
/
init-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
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
(use-package evil
:ensure t
:init
(setq evil-want-C-i-jump nil) ; org mode tab fix
; default is isearch. evil-seatch persists highlights on movements
;(setq evil-search-module 'evil-search)
(setq evil-magic 'very-magic)
(setq evil-want-C-w-in-emacs-state t)
(setq evil-want-fine-undo 'no)
(setq evil-shift-width 2)
:config
(evil-mode 1)
(use-package evil-surround
:ensure t
:config
(evil-define-key 'visual evil-surround-mode-map "s" 'evil-surround-region)
(evil-define-key 'visual evil-surround-mode-map "S" 'evil-substitute)
(global-evil-surround-mode 1))
(use-package evil-quickscope
:ensure t
:config
(require 'evil-quickscope)
(global-evil-quickscope-mode 1))
(use-package evil-numbers
:ensure t
:config
(define-key evil-normal-state-map (kbd "C-a") 'evil-numbers/inc-at-pt)
(define-key evil-normal-state-map (kbd "C-s") 'evil-numbers/dec-at-pt))
(use-package evil-numbers
:ensure t)
(use-package evil-matchit
:ensure t
:config
(global-evil-matchit-mode 1))
(use-package evil-visualstar
:ensure t
:config
(global-evil-visualstar-mode t))
(use-package evil-magit
:ensure t
:after magit)
(use-package move-text
:ensure t
:config
(define-key evil-normal-state-map (kbd "[ e") 'move-text-up)
(define-key evil-normal-state-map (kbd "] e") 'move-text-down))
(defun evil-unimpaired//find-relative-filename (offset)
(when buffer-file-name
(let* ((directory (f-dirname buffer-file-name))
(files (f--files directory (not (s-matches? "^\\.?#" it))))
(index (+ (-elem-index buffer-file-name files) offset))
(file (and (>= index 0) (nth index files))))
(when file
(f-expand file directory)))))
(defun evil-unimpaired/previous-file ()
(interactive)
(-if-let (filename (evil-unimpaired//find-relative-filename -1))
(find-file filename)
(user-error "No previous file")))
(defun evil-unimpaired/next-file ()
(interactive)
(-if-let (filename (evil-unimpaired//find-relative-filename 1))
(find-file filename)
(user-error "No next file")))
(defun evil-unimpaired/paste-above ()
(interactive)
(evil-insert-newline-above)
(evil-paste-after 1))
(defun evil-unimpaired/paste-below ()
(interactive)
(evil-insert-newline-below)
(evil-paste-after 1))
(defun evil-unimpaired/insert-space-above ()
(interactive)
(save-excursion
(evil-insert-newline-above)))
(defun evil-unimpaired/insert-space-below ()
(interactive)
(save-excursion
(evil-insert-newline-below)))
(defun evil-unimpaired/next-frame ()
(interactive)
(raise-frame (next-frame)))
(defun evil-unimpaired/previous-frame ()
(interactive)
(raise-frame (previous-frame)))
;; from tpope's unimpaired
(define-key evil-normal-state-map (kbd "[ SPC")
'evil-unimpaired/insert-space-above)
(define-key evil-normal-state-map (kbd "] SPC")
'evil-unimpaired/insert-space-below)
(define-key evil-visual-state-map (kbd "[ e") ":move'<--1")
(define-key evil-visual-state-map (kbd "] e") ":move'>+1")
(define-key evil-normal-state-map (kbd "[ f") 'evil-unimpaired/previous-file)
(define-key evil-normal-state-map (kbd "] f") 'evil-unimpaired/next-file)
(define-key evil-normal-state-map (kbd "[ h") 'diff-hl-previous-hunk)
(define-key evil-normal-state-map (kbd "] h") 'diff-hl-next-hunk)
(define-key evil-normal-state-map (kbd "[ t") 'evil-unimpaired/previous-frame)
(define-key evil-normal-state-map (kbd "] t") 'evil-unimpaired/next-frame)
(define-key evil-normal-state-map (kbd "[ w") 'previous-multiframe-window)
(define-key evil-normal-state-map (kbd "] w") 'next-multiframe-window)
;; select pasted text
(define-key evil-normal-state-map (kbd "g p") (kbd "` [ v ` ]"))
;; paste above or below with newline
(define-key evil-normal-state-map (kbd "[ p") 'evil-unimpaired/paste-above)
(define-key evil-normal-state-map (kbd "] p") 'evil-unimpaired/paste-below)
;move between buffers
(define-key evil-normal-state-map (kbd "] b") 'next-buffer)
(define-key evil-normal-state-map (kbd "[ b") 'previous-buffer)
;; indent on ret
(define-key evil-insert-state-map (kbd "RET") 'newline-and-indent)
(define-key evil-normal-state-map (kbd "SPC SPC") 'helm-M-x)
(define-key evil-visual-state-map (kbd "SPC SPC") 'helm-M-x)
;move between buffers
(define-key evil-normal-state-map (kbd "] b") 'next-buffer)
(define-key evil-normal-state-map (kbd "[ b") 'previous-buffer)
;move in wraps
(define-key evil-normal-state-map (kbd "j") 'evil-next-visual-line)
(define-key evil-normal-state-map (kbd "k") 'evil-previous-visual-line)
(define-key minibuffer-local-map (kbd "C-w") 'backward-kill-word)
(define-key minibuffer-local-map (kbd "C-r") 'evil-paste-from-register)
;; evil mappings in package list
(defun my-package-list-get-q-key ()
"Lookup the current meaning of `q` key in the active package-menu-mode"
(interactive)
(call-interactively (lookup-key package-menu-mode-map "q"))
)
(evil-set-initial-state 'package-menu-mode 'normal)
(evil-define-key 'normal package-menu-mode-map
;; bound when package-menu is initialized
;; for clearing filters.
"q" 'my-package-list-get-q-key
"d" 'package-menu-mark-delete
"i" 'package-menu-mark-install
"U" 'package-menu-mark-upgrades
"r" 'package-menu-refresh
"K" 'package-menu-describe-package
"u" 'package-menu-mark-unmark
"\177" 'package-menu-backup-unmark
"d" 'package-menu-mark-delete
"i" 'package-menu-mark-install
"U" 'package-menu-mark-upgrades
"r" 'package-menu-refresh
"/" 'package-menu-filter
"~" 'package-menu-mark-obsolete-for-deletion
"x" 'package-menu-execute
"?" 'package-menu-quick-help
)
(evil-define-key 'motion package-menu-mode-map
"q" 'my-package-list-get-q-key
"h" 'evil-backward-char
"j" 'evil-next-visual-line
"k" 'evil-previous-visual-line
"l" 'evil-forward-char
)
; shells
(evil-define-key 'insert comint-mode-map (kbd "C-p") 'comint-previous-input)
(evil-define-key 'insert comint-mode-map (kbd "C-n") 'comint-next-input)
(evil-define-key 'insert inferior-emacs-lisp-mode-map (kbd "C-p") 'comint-previous-input)
(evil-define-key 'insert inferior-emacs-lisp-mode-map (kbd "C-n") 'comint-next-input)
(define-key evil-motion-state-map "\C-]" nil)
)
(provide 'init-evil)