public
Created

  • Download Gist
evil-keys.el
Emacs Lisp
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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
 
 
;; There's a GREAT script at
;; https://github.com/cofi/dotfiles/blob/master/emacs.d/config/cofi-evil.el#L320
 
(setq evil-normal-state-tag (propertize "N" 'face '())
evil-emacs-state-tag (propertize "E" 'face '((:background "#93a1a1")))
evil-insert-state-tag (propertize "I" 'face '((:background "#93a1a1")))
evil-motion-state-tag (propertize "M" 'face '())
evil-visual-state-tag (propertize "V" 'face '())
evil-operator-state-tag (propertize "O" 'face '())
evil-cross-lines t
evil-want-C-w-in-emacs-state t)
 
(require 'evil)
(evil-mode 1)
(require 'surround)
(global-surround-mode 1)
 
(define-key evil-window-map "d" 'evil-delete-buffer) ;; C-w d
(define-key evil-window-map "\C-d" 'evil-delete-buffer) ;; C-w d
(define-key evil-normal-state-map "\C-s" 'save-buffer)
(define-key evil-insert-state-map "\C-s" 'save-buffer)
 
(define-key evil-normal-state-map (kbd "SPC") 'evil-scroll-page-down)
(define-key evil-normal-state-map (kbd "S-SPC") 'evil-scroll-page-up)
 
(define-key evil-normal-state-map "Y" (kbd "y$"))
(define-key evil-normal-state-map "Q" 'fill-paragraph)
(define-key evil-normal-state-map (kbd "M--") 'comment-dwim)
 
(define-key evil-normal-state-map "ga" 'org-agenda)
(define-key evil-normal-state-map "gf" 'ido-find-file)
(define-key evil-normal-state-map "gc" 'ido-switch-buffer)
(define-key evil-normal-state-map "gr" 'org-capture)
(define-key evil-normal-state-map "gm" 'notmuch-or-check)
(define-key evil-normal-state-map "gD" 'dired-jump)
(evil-define-key 'normal dired-mode-map "gD" 'dired-jump)
(define-key evil-normal-state-map "gM" 'compose-mail)
(define-key evil-normal-state-map "gs" 'eshell)
(define-key evil-normal-state-map "gG" 'magit-status)
(define-key evil-normal-state-map "go" 'ido-goto-symbol)
(define-key evil-normal-state-map "gp" 'tumblesocks-view-dashboard)
 
(define-key evil-normal-state-map "\M-P" 'evil-paste-pop-next)
(define-key evil-normal-state-map "\M-p" 'evil-paste-pop)
 
(define-key evil-normal-state-map "\M-a" 'execute-extended-command) ;; M-x
(define-key evil-emacs-state-map "\M-a" 'execute-extended-command) ;; M-x
(define-key evil-insert-state-map "\M-a" 'execute-extended-command) ;; M-x
 
(define-key evil-insert-state-map "\C-t" 'evil-normal-state)
(define-key evil-replace-state-map "\C-t" 'evil-normal-state)
(define-key evil-emacs-state-map "\C-t" 'evil-normal-state)
(define-key evil-normal-state-map "\C-t" 'evil-normal-state)
(define-key evil-motion-state-map "\C-t" 'evil-normal-state)
 
(define-key evil-normal-state-map "ZZ" nil)
(define-key evil-normal-state-map "ZQ" nil)
(evil-ex-define-cmd "wq" 'evil-write)
(evil-ex-define-cmd "q[uit]" 'evil-delete-buffer)
(evil-ex-define-cmd "qa[ll]" nil)
(evil-ex-define-cmd "wqa[ll]" 'evil-write)
(evil-ex-define-cmd "x[it]" 'evil-write)
 
;; Make ace jump look like a single command to evil
(require 'ace-jump-mode)
(defadvice ace-jump-word-mode (after evil activate)
(recursive-edit))
(defadvice ace-jump-char-mode (after evil activate)
(recursive-edit))
(defadvice ace-jump-line-mode (after evil activate)
(recursive-edit))
(defadvice ace-jump-done (after evil activate)
(exit-recursive-edit))
(define-key evil-normal-state-map (kbd "M-o") 'ace-jump-char-mode)
(define-key evil-normal-state-map (kbd "M-O") 'ace-jump-word-mode)
(define-key evil-operator-state-map (kbd "M-o") 'ace-jump-char-mode)
(define-key evil-operator-state-map (kbd "M-O") 'ace-jump-word-mode)
(define-key evil-visual-state-map (kbd "M-o") 'ace-jump-char-mode)
(define-key evil-visual-state-map (kbd "M-O") 'ace-jump-word-mode)
 
;; Notmuch ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(evil-define-key 'normal notmuch-search-mode-map
(kbd "q") 'notmuch-search-quit
(kbd "n") 'notmuch-search-next-thread
(kbd "p") 'notmuch-search-previous-thread
(kbd "RET") 'notmuch-search-show-thread)
 
;; Mail ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(evil-add-hjkl-bindings notmuch-search-mode-map 'emacs)
(evil-add-hjkl-bindings notmuch-show-mode-map 'emacs)
(evil-set-initial-state 'notmuch-search-mode 'emacs)
(evil-set-initial-state 'notmuch-show-mode 'emacs)
 
;; Magit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(evil-add-hjkl-bindings magit-branch-manager-mode-map 'emacs
"K" 'magit-discard-item
"L" 'magit-key-mode-popup-logging)
(evil-add-hjkl-bindings magit-status-mode-map 'emacs
"K" 'magit-discard-item
"l" 'magit-key-mode-popup-logging
"h" 'magit-toggle-diff-refine-hunk)
(evil-set-initial-state 'magit-log-edit-mode 'insert)
 
;; ERC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(evil-set-initial-state 'erc-mode 'normal)
(evil-define-key 'normal erc-mode-map
"0" 'erc-bol
;; "dd" "0D"
;; "cc" "0C"
"M-d" 'erc-bol
"." 'ignore
"I" "0i"
(kbd "RET") 'erc-send-current-line)
(evil-define-key 'insert erc-mode-map
(kbd "M-c") 'erc-previous-command
(kbd "M-t") 'erc-next-command
(kbd "M-d") 'erc-bol
(kbd "RET") 'erc-send-current-line)
 
;; comint-mode ;;;;;;;;;;;;;;;;;;;;;;;;;
(evil-define-key 'normal comint-mode-map
"0" 'comint-bol
;; "dd" "0D"
;; "cc" "0C"
"M-d" 'comint-bol
"I" "0i"
(kbd "RET") 'comint-send-input)
(evil-define-key 'insert comint-mode-map
(kbd "M-c") 'comint-previous-input
(kbd "M-m") 'comint-previous-matching-input-from-input
(kbd "M-w") 'comint-next-matching-input-from-input
(kbd "M-t") 'comint-next-input
(kbd "M-d") 'comint-bol
(kbd "RET") 'comint-send-input)
 
 
;; Org-mode fixes
(evil-define-key 'normal org-mode-map
(kbd "RET") 'org-open-at-point
"za" 'org-cycle
"zA" 'org-shifttab
"zm" 'hide-body
"zr" 'show-all
"zo" 'show-subtree
"zO" 'show-all
"zc" 'hide-subtree
"zC" 'hide-all
(kbd "M-j") 'org-shiftleft
(kbd "M-k") 'org-shiftright
(kbd "M-H") 'org-metaleft
(kbd "M-J") 'org-metadown
(kbd "M-K") 'org-metaup
(kbd "M-L") 'org-metaright)
 
(evil-define-key 'normal orgstruct-mode-map
(kbd "RET") 'org-open-at-point
"za" 'org-cycle
"zA" 'org-shifttab
"zm" 'hide-body
"zr" 'show-all
"zo" 'show-subtree
"zO" 'show-all
"zc" 'hide-subtree
"zC" 'hide-all
(kbd "M-j") 'org-shiftleft
(kbd "M-k") 'org-shiftright
(kbd "M-H") 'org-metaleft
(kbd "M-J") 'org-metadown
(kbd "M-K") 'org-metaup
(kbd "M-L") 'org-metaright)
 
;; Comint ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; normal mode: Enter should send line, just like in erc
;; retrieve things from history
 
;; Ergo emacs keybindings. Gosh I love these. ;;;;;;;;;;;;;;;;;;;;;;;;
 
(loop for map in (list minibuffer-local-map
evil-insert-state-map
evil-emacs-state-map) do
(define-key map (kbd "M-h") 'backward-char)
(define-key map (kbd "M-n") 'forward-char)
(define-key map (kbd "M-c") 'previous-line)
(define-key map (kbd "M-t") 'next-line)
(define-key map (kbd "M-g") 'backward-word)
(define-key map (kbd "M-r") 'forward-word)
(define-key map (kbd "M-G") 'backward-paragraph)
(define-key map (kbd "M-R") 'forward-paragraph)
(define-key map (kbd "M-d") 'beginning-of-line)
(define-key map (kbd "M-D") 'end-of-line)
(define-key map (kbd "M-C") 'scroll-down)
(define-key map (kbd "M-T") 'scroll-up)
(define-key map (kbd "M-H") 'beginning-of-buffer)
(define-key map (kbd "M-N") 'end-of-buffer)
(define-key map (kbd "M-l") 'recenter-top-bottom)
(define-key map (kbd "M-e") 'delete-backward-char)
(define-key map (kbd "M-u") 'delete-char)
(define-key map (kbd "M-.") 'backward-kill-word)
(define-key map (kbd "M-p") 'kill-word)
;; ^^^ This is paste-pop so only do this in insert+emacs mode!
(define-key map (kbd "M-q") 'kill-region)
(define-key map (kbd "M-j") 'kill-ring-save)
(define-key map (kbd "M-k") 'yank)
(define-key map (kbd "M-K") 'yank-pop)
;; (define-key map (kbd "M-J") 'copy-all)
;; (define-key map (kbd "M-Q") 'cut-all)
(define-key map (kbd "M-i") 'kill-line)
(define-key map (kbd "M-I") 'kill-line-backward)
(define-key map (kbd "M--") 'comment-dwim)
(define-key map (kbd "M-z") 'toggle-letter-case)
(define-key map (kbd "M-;") 'flyspell-auto-correct-previous-word)
)
;; Fix ido and friends. Sheesh :/
(define-key minibuffer-local-map (kbd "M-c") 'previous-history-element)
(define-key minibuffer-local-map (kbd "M-t") 'next-history-element)
 
(add-hook 'ido-setup-hook 'ido-my-keys)
(defun ido-my-keys ()
"Add my keybindings for ido."
(define-key ido-completion-map (kbd "M-h") 'ido-prev-match)
(define-key ido-completion-map (kbd "M-n") 'ido-next-match)
;; (define-key ido-completion-map " " 'ido-next-match)
)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.