Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
;; 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)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.