Guest User

init.d/evil.el

a guest
Oct 31st, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. (require 'evil)
  2. (evil-mode)
  3. (global-evil-leader-mode)
  4. (global-evil-mc-mode)
  5.  
  6. (setq
  7. evil-esc-delay 0
  8. evil-regexp-search t
  9. evil-vsplit-window-right t
  10. evil-leader/in-all-states t
  11. evil-leader/no-prefix-mode-rx '("dired-mode")
  12. )
  13.  
  14. (defmacro define-evil-keys (defs)
  15. `(cl-loop for (states bind fn) in ,defs
  16. do (cl-loop for state across (symbol-name states)
  17. do (define-key
  18. (cl-case state
  19. (?n evil-normal-state-map)
  20. (?v evil-visual-state-map)
  21. (?m evil-motion-state-map)
  22. (?i evil-insert-state-map))
  23. bind
  24. fn))))
  25.  
  26. (define-evil-keys `((nvm " " evil-ex)
  27. (nm "s" evil-window-next)
  28. (nm "(" evil-previous-open-brace)
  29. (nm ")" evil-next-close-brace)
  30. (m "gf" icicle-find-file) ; motion state doesn't have this by default, oddly
  31. ))
  32.  
  33. (evil-leader/set-leader "," nil)
  34. (evil-leader/set-key
  35. "b" #'switch-to-buffer
  36. "B" #'ibuffer
  37. "e" #'eval-expression
  38. "n" #'make-frame
  39. "o" #'occur
  40.  
  41. "ss" #'smerge-mode
  42. "sn" #'smerge-next
  43. "sp" #'smerge-prev
  44. (kbd "s RET") #'smerge-keep-current
  45. "so" #'smerge-keep-other
  46. )
  47.  
  48. (defmacro init/evil-setup-bindings-aux (mode state &rest bindings)
  49. (let ((mode-map (intern (concat (symbol-name mode) "-map"))))
  50. `(progn
  51. (evil-set-initial-state ',mode ',state)
  52. ,@(cl-loop for (key binding) in bindings
  53. collecting `(evil-define-key ',state ,mode-map ,key ,binding)))))
  54.  
  55. (defmacro init/evil-setup-bindings (mode state &rest bindings)
  56. `(init/evil-setup-bindings-aux ,mode ,state
  57. (" " 'evil-ex)
  58. ("s" 'evil-window-next)
  59. ("gg" 'evil-goto-first-line)
  60. ("G" 'evil-goto-line)
  61. ("gf" 'icicle-find-file)
  62. ,@bindings))
  63.  
  64. (init/evil-setup-bindings ibuffer-mode motion
  65. ((kbd "RET") 'ibuffer-visit-buffer))
  66.  
  67. (init/evil-setup-bindings Custom-mode motion)
  68.  
  69. (init/evil-setup-bindings package-menu-mode motion)
  70.  
  71. (init/evil-setup-bindings dired-mode emacs
  72. ("j" 'dired-next-line)
  73. ("k" 'dired-previous-line)
  74. ("/" 'evil-search-forward))
  75.  
  76. (init/evil-setup-bindings compilation-mode motion
  77. ("r" 'recompile))
  78.  
  79. ;; jk -> Esc mapping from https://zuttobenkyou.wordpress.com/2011/02/15/some-thoughts-on-emacs-and-vim/ (ctrl-f cofi)
  80. (define-key evil-insert-state-map "j" #'cofi/maybe-exit)
  81. (evil-define-command cofi/maybe-exit ()
  82. :repeat change
  83. (interactive)
  84. (let ((modified (buffer-modified-p)))
  85. (insert "j")
  86. (let ((evt (read-event nil nil 0.5)))
  87. (cond
  88. ((null evt) (message ""))
  89. ((and (integerp evt) (char-equal evt ?k))
  90. (delete-char -1) ; delete k
  91. ;; for c/c++, don't leave whitespace-only lines (TODO: figure out a better approach here since esc doesn't do this)
  92. (when (and (or (eq major-mode 'c-mode) (eq major-mode 'c++-mode))
  93. (string-match "^[ \t]+$" (thing-at-point 'line)))
  94. (beginning-of-line)
  95. (kill-line))
  96. (set-buffer-modified-p modified)
  97. (push 'escape unread-command-events))
  98. (t (setq unread-command-events (append unread-command-events
  99. (list evt))))))))
Add Comment
Please, Sign In to add comment