Evil experiences
Tom Short
tshort.rlists at gmail.com
Thu Sep 8 01:55:34 CEST 2011
Hi everyone,
I really like evil. (That's hard to write with a straight face.) I've
tried viper/vimpulse before, but it never stuck. I'm curious how other
folks set up or tweak their setup. See below for my setup. I tend to
mostly use R/ESS and org-mode.
One thing that helped me a lot is setting up a "super-ESC" key that
switches to normal state. Sometimes I would get into a buffer that
wouldn't start in any state known to evil, and so C-z and ESC didn't
do what I wanted. For this "super-ESC", I used David Andersson's
key-chord.el for simultaneous j & k key presses.
For some modes, I didn't like the use of evil-make-overriding-map. I
tried this with Org's agenda mode. The end results was too much of a
mish-mash of keys. I ended up just assigning j and k in
org-agenda-mode-map and left normal state as is.
Once evil settles down, it'd be nice to have a place to share configurations.
Here are my .emacs entries related to evil. Comments welcome. - Tom
;;;;
;;;; EVIL
;;;;
(add-to-list 'load-path "~/.emacs.d/evil")
(require 'evil)
(evil-mode 1)
;; Miscellaneous
(setq evil-emacs-state-cursor '("red" box))
;; Movements
(define-key evil-motion-state-map " " 'evil-scroll-down)
(define-key evil-motion-state-map (kbd "S-SPC") 'evil-scroll-up)
(define-key evil-motion-state-map "H" 'evil-first-non-blank)
(define-key evil-motion-state-map "L" 'evil-end-of-line)
;; General command-type stuff
(define-key evil-normal-state-map ",w" 'save-buffer) ; save
(define-key evil-normal-state-map ",s" 'save-buffer) ; (I can't make
up my mind on w vs. s)
(define-key evil-normal-state-map ",d" 'kill-this-buffer)
(define-key evil-normal-state-map ",a" 'my-anything) ; emacs anything
(define-key evil-normal-state-map ",b" 'bs-show) ; buffer show (bs)
(define-key evil-normal-state-map ",e" 'wn-explorer) ; launch an
explorer directory
(define-key evil-normal-state-map ",R" 'sunrise-cd) ; two-pane
directory based on current dir
(define-key evil-normal-state-map ",r" 'sunrise) ; two-pane directory
(define-key evil-normal-state-map ",o" 'org-agenda) ; access org agenda buffer
(define-key evil-normal-state-map ",f" 'ace-jump-mode)
;; Window movements
(global-set-key "\C-w" 'evil-window-map)
(defun my-window-vsplit-and-go ()
"Split the window vertically, go to the new window, and call buffer show."
(interactive)
(progn
(split-window-vertically)
(evil-window-down 1)
(bs-show nil)
))
(defun my-window-hsplit-and-go ()
"Split the window horizontally, go to the new window, and call buffer show."
(interactive)
(progn
(split-window-horizontally)
(evil-window-right 1)
(bs-show nil)
))
(define-key evil-window-map "s" 'my-window-vsplit-and-go)
(define-key evil-window-map "v" 'my-window-hsplit-and-go)
(defun my-window-maximize ()
"Maximize the current window. (This is the same as C-w _ then C-w |.)"
(interactive)
(progn
(evil-window-set-height nil)
(evil-window-set-width nil)
))
(defun my-window-switch-and-maximize () ; nice for toggling between windows
"Go to the previous window and maximize it. (This is the same as C-w
C-w, C-w _ then C-w |.)"
(interactive)
(progn
(evil-window-prev nil)
(evil-window-set-height nil)
(evil-window-set-width nil)
))
(define-key evil-window-map "f" 'my-window-maximize) ; "full"
(define-key evil-window-map "g" 'my-window-switch-and-maximize) ; "go"
;; R / ESS stuff
; I want the following to work in any mode, not just ess-mode
(define-key evil-normal-state-map ",," 'ess-eval-paragraph)
(define-key evil-normal-state-map ",g" 'ess-eval-paragraph-and-go)
(define-key evil-visual-state-map ",," 'ess-eval-region)
(define-key evil-visual-state-map ",g" 'ess-eval-region-and-go)
(eval-after-load 'ess-help
'(progn
(add-hook 'ess-help-mode-hook 'evil-change-to-initial-state)
))
;; jump to the prompt and go to insert mode
(evil-define-key 'normal inferior-ess-mode-map "i" 'my-R-insert)
(evil-define-key 'normal inferior-ess-mode-map "I" 'my-R-insert)
(evil-define-key 'normal inferior-ess-mode-map "A" 'my-R-insert)
(defun my-R-insert ()
(interactive)
(end-of-buffer)
(comint-show-maximum-output)
(evil-insert 0)
)
(evil-define-key 'normal inferior-ess-mode-map (kbd "C-j")
'comint-next-matching-input-from-input)
(evil-define-key 'normal inferior-ess-mode-map (kbd "C-k")
'comint-previous-matching-input-from-input)
;; Lisp
(evil-define-key 'visual emacs-lisp-mode-map ",," 'eval-region)
;; Org mode
; most taken from here:
; http://zuttobenkyou.wordpress.com/2011/02/15/some-thoughts-on-emacs-and-vim/
(defun always-insert-item ()
(interactive)
(if (not (org-in-item-p))
(insert "\n- ")
(org-insert-item)))
(evil-define-key 'normal org-mode-map "O" (lambda ()
(interactive)
(end-of-line)
(org-insert-heading t)
(evil-append nil)
))
(evil-define-key 'normal org-mode-map "o" (lambda ()
(interactive)
(end-of-line)
(always-insert-item)
(evil-append nil)
))
(evil-define-key 'normal org-mode-map "t" 'org-todo) ; mark a TODO item as DONE
(evil-define-key 'normal org-mode-map "-" 'org-cycle-list-bullet) ;
change bullet style
;; (evil-define-key 'normal org-mode-map "L" 'org-shiftright)
;; (evil-define-key 'normal org-mode-map "H" 'org-shiftleft)
;; (evil-define-key 'normal org-mode-map "K" 'org-shiftup)
;; (evil-define-key 'normal org-mode-map "J" 'org-shiftdown)
(evil-define-key 'normal org-mode-map (kbd "M-l") 'org-metaright)
(evil-define-key 'normal org-mode-map (kbd "M-h") 'org-metaleft)
(evil-define-key 'normal org-mode-map (kbd "M-k") 'org-metaup)
(evil-define-key 'normal org-mode-map (kbd "M-j") 'org-metadown)
(evil-define-key 'normal org-mode-map (kbd "M-L") 'org-shiftmetaright)
(evil-define-key 'normal org-mode-map (kbd "M-H") 'org-shiftmetaleft)
(evil-define-key 'normal org-mode-map (kbd "M-K") 'org-shiftmetaup)
(evil-define-key 'normal org-mode-map (kbd "M-J") 'org-shiftmetadown)
;;; org agenda -- leave in emacs mode but add j & k
(define-key org-agenda-mode-map "j" 'evil-next-line)
(define-key org-agenda-mode-map "k" 'evil-previous-line)
;;; BS-menu
(eval-after-load 'bs
'(progn
;; use the standard bs bindings as a base
(evil-make-overriding-map bs-mode-map 'normal t)
(evil-define-key 'motion bs-mode-map "h" 'evil-backward-char)
(evil-define-key 'motion bs-mode-map "j" 'bs-down)
(evil-define-key 'motion bs-mode-map "k" 'bs-up)
(evil-define-key 'motion bs-mode-map "l" 'evil-forward-char)
))
;;; key chords for simultaneous key presses for common commands
(require 'key-chord) ; for mapping simultaneous key presses
;; http://www.emacswiki.org/emacs/key-chord.el
(key-chord-mode 1)
(key-chord-define-global "jk" 'evil-normal-state) ; super ESC
(key-chord-define-global "JK" 'evil-emacs-state)
(key-chord-define-global "df" 'evil-window-map)
(key-chord-define evil-window-map "df" 'evil-window-prev) ; df twice
(DOESN'T WORK)
More information about the implementations-list
mailing list