Update evil settings

This commit is contained in:
Tom Willemse 2016-02-10 11:13:12 +01:00
parent 31809b70e7
commit 2d95e082f9
2 changed files with 169 additions and 13 deletions

View file

@ -141,17 +141,6 @@ MODE1 is enabled and vice-versa."
"Set the `disabled' property for each item in FUNCTIONS to nil."
(mapc #'(lambda (f) (put f 'disabled nil)) functions))
(defun oni:maybe-switch-to-normal-state ()
"Switch the current buffer to normal state.
Only do this when the mode is not in emacs state by default."
(unless (memql major-mode (oni:modes-starting-in 'emacs))
(evil-normal-state)))
(defun oni:modes-starting-in (state)
"Get a list of the modes whose default state is STATE."
(symbol-value (evil-state-property state :modes)))
;;;; Module-specific settings
(auto-init appt)
@ -716,6 +705,17 @@ Only do this when the mode is not in emacs state by default."
;; Update diff-hl when magit changes something.
(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh t)
;; Clear all keybindings from evil-insert-state so I can use normal
;; Emacs keybindings.
(add-hook 'evil-mode-hook 'oni:evil-clear-insert-state-keys)
;; Make C-g do the same thing as ESC in most evil states. This should
;; always be done _after_ `oni:evil-clear-insert-state-keys'.
(add-hook 'evil-mode-hook 'oni:evil-set-normal-state-key :append)
;; Change all keybindings for use with Colemak.
(add-hook 'evil-mode-hook 'oni:evil-setup-colemak)
(oni:add-hooks 'texinfo-mode-hook
#'outline-minor-mode)
@ -832,8 +832,8 @@ Only do this when the mode is not in emacs state by default."
(global-wakatime-mode)
(evil-mode)
(kill-local-variable 'mode-line-format)
(when (string-equal (system-name) "drd")
(require 'evil-colemak))
;; (when (string-equal (system-name) "drd")
;; (require 'colemak-evil))
(global-evil-surround-mode))
(with-eval-after-load 'ruby

View file

@ -0,0 +1,156 @@
;;; oni-evil.el --- Extra Evil mode functions and commands -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Tom Willemse
;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Here are some Evil-related commands and functions.
;;; Code:
(require 'evil-states)
(require 'evil-vars)
;;;###autoload
(defun oni:evil-clear-insert-state-keys ()
"Remove all keybindings from the `evil-insert-state-map'."
(setcdr evil-insert-state-map nil))
;;;###autoload
(defun oni:maybe-switch-to-normal-state ()
"Switch the current buffer to normal state.
Only do this when the mode is not in Emacs state by default."
(unless (memql major-mode (oni:modes-starting-in 'emacs))
(evil-normal-state)))
;;;###autoload
(defun oni:modes-starting-in (state)
"Get a list of the modes whose default state is STATE."
(symbol-value (evil-state-property state :modes)))
;;;###autoload
(defun oni:evil-set-normal-state-key ()
"Set `C-g' to go back to evil-normal-state, like ESC."
(let ((evil-modes (delq 'emacs (mapcar #'car evil-state-properties))))
(dolist (mode evil-modes)
(let ((keymap-symbol
(intern (concat "evil-" (symbol-name mode) "-state-map"))))
(define-key (symbol-value keymap-symbol)
(kbd "C-g") #'evil-normal-state)))))
;;;###autoload
(defun oni:evil-setup-colemak ()
"Swap keys to match the Colemak layout."
(define-key evil-normal-state-map "s" 'evil-delete)
(define-key evil-normal-state-map "S" 'evil-delete-line)
(define-key evil-normal-state-map "r" 'evil-substitute)
(define-key evil-normal-state-map "R" 'evil-change-whole-line)
(define-key evil-normal-state-map "p" 'evil-replace)
(define-key evil-normal-state-map "P" 'evil-replace-state)
(define-key evil-normal-state-map ";" 'evil-paste-after)
(define-key evil-normal-state-map ":" 'evil-paste-before)
(define-key evil-normal-state-map "y" 'evil-open-below)
(define-key evil-normal-state-map "Y" 'evil-open-above)
(define-key evil-normal-state-map "j" 'evil-yank)
(define-key evil-normal-state-map "J" 'evil-yank-line)
(define-key evil-normal-state-map "N" 'evil-join)
(define-key evil-normal-state-map "u" 'evil-insert)
(define-key evil-normal-state-map "U" 'evil-insert-line)
(define-key evil-normal-state-map "l" 'undo)
(define-key evil-normal-state-map "d" nil)
(define-key evil-normal-state-map "d&" 'evil-ex-repeat-global-substitute)
(define-key evil-normal-state-map "d8" 'what-cursor-position)
(define-key evil-normal-state-map "da" 'what-cursor-position)
(define-key evil-normal-state-map "di" 'evil-insert-resume)
(define-key evil-normal-state-map "dJ" 'evil-join-whitespace)
(define-key evil-normal-state-map "dq" 'evil-fill-and-move)
(define-key evil-normal-state-map "dw" 'evil-fill)
(define-key evil-normal-state-map "du" 'evil-downcase)
(define-key evil-normal-state-map "dU" 'evil-upcase)
(define-key evil-normal-state-map "df" 'find-file-at-point)
(define-key evil-normal-state-map "dF" 'evil-find-file-at-point-with-line)
(define-key evil-normal-state-map "d?" 'evil-rot13)
(define-key evil-normal-state-map "d~" 'evil-invert-case)
(define-key evil-normal-state-map "d;" 'goto-last-change)
(define-key evil-normal-state-map "d," 'goto-last-change-reverse)
(define-key evil-normal-state-map "i" nil)
(define-key evil-normal-state-map "I" nil)
(define-key evil-normal-state-map "o" nil)
(define-key evil-normal-state-map "O" nil)
(define-key evil-normal-state-map "g" nil)
(define-key evil-window-map "g" 'evil-window-top-left)
(define-key evil-window-map "r" 'evil-window-split)
(define-key evil-window-map "R" 'evil-window-split)
(define-key evil-window-map "p" 'evil-window-rotate-downwards)
(define-key evil-window-map "P" 'evil-window-rotate-upwards)
(define-key evil-window-map "p" 'evil-window-mru)
(define-key evil-window-map "y" 'delete-other-windows)
(define-key evil-window-map "n" 'evil-window-down)
(define-key evil-window-map "N" 'evil-window-move-very-bottom)
(define-key evil-window-map "k" 'evil-window-new)
(define-key evil-window-map "e" 'evil-window-up)
(define-key evil-window-map "E" 'evil-window-move-very-top)
(define-key evil-window-map "i" 'evil-window-right)
(define-key evil-window-map "I" 'evil-window-move-far-right)
(define-key evil-motion-state-map "f" 'evil-forward-word-end)
(define-key evil-motion-state-map "F" 'evil-forward-WORD-end)
(define-key evil-motion-state-map "t" 'evil-find-char)
(define-key evil-motion-state-map "T" 'evil-find-char-backward)
(define-key evil-motion-state-map "g" 'evil-find-char-to)
(define-key evil-motion-state-map "G" 'evil-find-char-to-backward)
(define-key evil-motion-state-map "D" 'evil-goto-line)
(define-key evil-motion-state-map "o" 'evil-repeat-find-char)
(define-key evil-motion-state-map "O" 'evil-ex)
(define-key evil-motion-state-map "j" 'evil-yank)
(define-key evil-motion-state-map "J" 'evil-yank-line)
(define-key evil-motion-state-map "n" 'evil-next-line)
(define-key evil-motion-state-map "k" 'evil-search-next)
(define-key evil-motion-state-map "K" 'evil-search-previous)
(define-key evil-motion-state-map "e" 'evil-previous-line)
(define-key evil-motion-state-map "E" 'evil-lookup)
(define-key evil-motion-state-map "i" 'evil-forward-char)
(define-key evil-motion-state-map "I" 'evil-window-bottom)
(define-key evil-motion-state-map "d" nil)
(define-key evil-motion-state-map "dd" 'evil-goto-definition)
(define-key evil-motion-state-map "de" 'evil-backward-word-end)
(define-key evil-motion-state-map "dE" 'evil-backward-WORD-end)
(define-key evil-motion-state-map "dg" 'evil-goto-first-line)
(define-key evil-motion-state-map "dj" 'evil-next-visual-line)
(define-key evil-motion-state-map "dk" 'evil-previous-visual-line)
(define-key evil-motion-state-map "d0" 'evil-beginning-of-visual-line)
(define-key evil-motion-state-map "d_" 'evil-last-non-blank)
(define-key evil-motion-state-map "d^" 'evil-first-non-blank-of-visual-line)
(define-key evil-motion-state-map "dm" 'evil-middle-of-visual-line)
(define-key evil-motion-state-map "d$" 'evil-end-of-visual-line)
(define-key evil-motion-state-map "d\C-]" 'find-tag)
(define-key evil-visual-state-map "P" 'evil-change)
(define-key evil-visual-state-map "y" 'exchange-point-and-mark)
(define-key evil-visual-state-map "Y" 'evil-visual-exchange-corners)
(define-key evil-visual-state-map "U" 'evil-insert)
(define-key evil-visual-state-map "u" evil-inner-text-objects-map)
(define-key evil-visual-state-map "l" 'evil-downcase)
(define-key evil-visual-state-map "L" 'evil-upcase))
(provide 'oni-evil)
;;; oni-evil.el ends here