Emacs config utilizing prelude as a base
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.7 KiB

  1. ;;; prelude-evil.el --- Emacs Prelude: evil-mode configuration.
  2. ;;
  3. ;; Copyright © 2011-2020 Bozhidar Batsov
  4. ;;
  5. ;; Author: Bozhidar Batsov <bozhidar@batsov.com>
  6. ;; URL: http://batsov.com/prelude
  7. ;; Version: 1.0.0
  8. ;; Keywords: convenience
  9. ;; This file is not part of GNU Emacs.
  10. ;;; Commentary:
  11. ;; Some basic configuration for evil-mode.
  12. ;;; License:
  13. ;; This program is free software; you can redistribute it and/or
  14. ;; modify it under the terms of the GNU General Public License
  15. ;; as published by the Free Software Foundation; either version 3
  16. ;; of the License, or (at your option) any later version.
  17. ;;
  18. ;; This program is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;; GNU General Public License for more details.
  22. ;;
  23. ;; You should have received a copy of the GNU General Public License
  24. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  25. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  26. ;; Boston, MA 02110-1301, USA.
  27. ;;; Code:
  28. ;;; goto-chg lets you use the g-; and g-, to go to recent changes
  29. ;;; evil-visualstar enables searching visual selection with *
  30. ;;; evil-numbers enables vim style numeric incrementing and decrementing
  31. (prelude-require-packages '(evil goto-chg evil-surround evil-visualstar evil-numbers))
  32. (require 'evil-visualstar)
  33. (setq evil-mode-line-format 'before)
  34. (setq evil-emacs-state-cursor '("red" box))
  35. (setq evil-normal-state-cursor '("gray" box))
  36. (setq evil-visual-state-cursor '("gray" box))
  37. (setq evil-insert-state-cursor '("gray" bar))
  38. (setq evil-motion-state-cursor '("gray" box))
  39. ;; prevent esc-key from translating to meta-key in terminal mode
  40. (setq evil-esc-delay 0)
  41. (evil-mode 1)
  42. (global-evil-surround-mode 1)
  43. (define-key evil-normal-state-map (kbd "C-A")
  44. 'evil-numbers/inc-at-pt)
  45. (define-key evil-normal-state-map (kbd "C-S-A")
  46. 'evil-numbers/dec-at-pt)
  47. ;;
  48. ;; Other useful Commands
  49. ;;
  50. (evil-ex-define-cmd "W" 'evil-write-all)
  51. (evil-ex-define-cmd "Tree" 'speedbar-get-focus)
  52. (evil-ex-define-cmd "linum" 'linum-mode)
  53. (evil-ex-define-cmd "Align" 'align-regexp)
  54. (defun prelude-yank-to-end-of-line ()
  55. "Yank to end of line."
  56. (interactive)
  57. (evil-yank (point) (point-at-eol)))
  58. (define-key evil-normal-state-map
  59. (kbd "Y") 'prelude-yank-to-end-of-line)
  60. (defun prelude-shift-left-visual ()
  61. "Shift left and restore visual selection."
  62. (interactive)
  63. (evil-shift-left (region-beginning) (region-end))
  64. (evil-normal-state)
  65. (evil-visual-restore))
  66. (defun prelude-shift-right-visual ()
  67. "Shift right and restore visual selection."
  68. (interactive)
  69. (evil-shift-right (region-beginning) (region-end))
  70. (evil-normal-state)
  71. (evil-visual-restore))
  72. (define-key evil-visual-state-map (kbd ">") 'prelude-shift-right-visual)
  73. (define-key evil-visual-state-map (kbd "<") 'prelude-shift-left-visual)
  74. ;; Scrolling
  75. (defun prelude-evil-scroll-down-other-window ()
  76. (interactive)
  77. (scroll-other-window))
  78. (defun prelude-evil-scroll-up-other-window ()
  79. (interactive)
  80. (scroll-other-window '-))
  81. (define-key evil-normal-state-map
  82. (kbd "C-S-d") 'prelude-evil-scroll-down-other-window)
  83. (define-key evil-normal-state-map
  84. (kbd "C-S-u") 'prelude-evil-scroll-up-other-window)
  85. ;;
  86. ;; Magit from avsej
  87. ;;
  88. (evil-add-hjkl-bindings magit-log-mode-map 'emacs)
  89. (evil-add-hjkl-bindings magit-commit-mode-map 'emacs)
  90. (evil-add-hjkl-bindings magit-branch-manager-mode-map 'emacs
  91. "K" 'magit-discard
  92. "L" 'magit-log)
  93. (evil-add-hjkl-bindings magit-status-mode-map 'emacs
  94. "K" 'magit-discard
  95. "l" 'magit-log
  96. "h" 'magit-diff-toggle-refine-hunk)
  97. (setq evil-shift-width 2)
  98. ;;; enable avy with evil-mode
  99. (define-key evil-normal-state-map (kbd "SPC") 'avy-goto-word-1)
  100. ;;; snagged from Eric S. Fraga
  101. ;;; http://lists.gnu.org/archive/html/emacs-orgmode/2012-05/msg00153.html
  102. (defun prelude-evil-key-bindings-for-org ()
  103. ;;(message "Defining evil key bindings for org")
  104. (evil-declare-key 'normal org-mode-map
  105. "gk" 'outline-up-heading
  106. "gj" 'outline-next-visible-heading
  107. "H" 'org-beginning-of-line ; smarter behaviour on headlines etc.
  108. "L" 'org-end-of-line ; smarter behaviour on headlines etc.
  109. "t" 'org-todo ; mark a TODO item as DONE
  110. ",c" 'org-cycle
  111. (kbd "TAB") 'org-cycle
  112. ",e" 'org-export-dispatch
  113. ",n" 'outline-next-visible-heading
  114. ",p" 'outline-previous-visible-heading
  115. ",t" 'org-set-tags-command
  116. ",u" 'outline-up-heading
  117. "$" 'org-end-of-line ; smarter behaviour on headlines etc.
  118. "^" 'org-beginning-of-line ; ditto
  119. "-" 'org-ctrl-c-minus ; change bullet style
  120. "<" 'org-metaleft ; out-dent
  121. ">" 'org-metaright ; indent
  122. ))
  123. (prelude-evil-key-bindings-for-org)
  124. (provide 'prelude-evil)