Difference between revisions of "Evil"
(toc and more) |
|||
Line 1: | Line 1: | ||
'''Evil''' is an '''e'''xtensible '''vi''' '''l'''ayer for Emacs. It provides Vim features like Visual selection and text objects, and is the successor to the now defunct vimpulse and vim-mode. | '''Evil''' is an '''e'''xtensible '''vi''' '''l'''ayer for Emacs. It provides Vim features like Visual selection and text objects, and is the successor to the now defunct vimpulse and vim-mode. | ||
− | = | + | = Installation = |
Evil comes prebuilt in emacs24. | Evil comes prebuilt in emacs24. | ||
In Emacs23, Evil can be downloaded and installed using [[el-get]] with: {{Command|el-get-install RET evil RET}}. | In Emacs23, Evil can be downloaded and installed using [[el-get]] with: {{Command|el-get-install RET evil RET}}. | ||
− | == | + | |
+ | |||
+ | == Manual install == | ||
+ | |||
Alternatively, Evil lives in a Git repository. To download Evil, do: | Alternatively, Evil lives in a Git repository. To download Evil, do: | ||
Line 12: | Line 15: | ||
git clone git://gitorious.org/evil/evil.git | git clone git://gitorious.org/evil/evil.git | ||
− | If you don't have Git, just head over to [https://gitorious.org/evil/evil/commits/master Gitorious] and click the ''"Download master as tar.gz"'' link (extract with | + | If you don't have Git, just head over to [https://gitorious.org/evil/evil/commits/master Gitorious] and click the ''"Download master as tar.gz"'' link (extract with tar -xzf master.tar.gz). |
− | |||
− | |||
− | If you installed it manually, move Evil to ~/.emacs.d/evil (or somewhere else in your | + | If you installed it manually, move Evil to {{Filename|~/.emacs.d/evil}} (or somewhere else in your load-path). |
In any case, add the following lines to ~/.emacs: | In any case, add the following lines to ~/.emacs: | ||
Line 24: | Line 25: | ||
− | Evil requires [UndoTree | + | Evil requires [[UndoTree]] in the load-path for linear undo and undo branches. Otherwise, Evil uses regular Emacs undo. |
− | + | = Documentation = | |
A brief [https://gitorious.org/evil/evil/blobs/raw/doc/doc/evil.pdf PDF manual] is available in the /doc subdirectory. | A brief [https://gitorious.org/evil/evil/blobs/raw/doc/doc/evil.pdf PDF manual] is available in the /doc subdirectory. | ||
− | + | = Configuration = | |
+ | |||
One thing I would recommend to any ex vimmer is to make escape to quit actually pretty much anything (like pending prompts in the minibuffer): | One thing I would recommend to any ex vimmer is to make escape to quit actually pretty much anything (like pending prompts in the minibuffer): | ||
Line 54: | Line 56: | ||
(define-key evil-visual-state-map "\C-w" 'evil-delete) | (define-key evil-visual-state-map "\C-w" 'evil-delete) | ||
+ | == Use fine grain undo == | ||
In insert mode, Evil uses linear undo. If you want fine grain undo: | In insert mode, Evil uses linear undo. If you want fine grain undo: | ||
Line 60: | Line 63: | ||
but remember, we shouldn't stay long in insert mode. | but remember, we shouldn't stay long in insert mode. | ||
+ | |||
+ | == Use keychords to go back to normal mode == | ||
If you'd like to type jj or jk in insert mode to go back to normal mode, you may use [[key-chord]]: | If you'd like to type jj or jk in insert mode to go back to normal mode, you may use [[key-chord]]: | ||
Line 65: | Line 70: | ||
(key-chord-define evil-insert-state-map "jj" 'evil-normal-state) | (key-chord-define evil-insert-state-map "jj" 'evil-normal-state) | ||
− | + | == Load config only when we call evil-mode == | |
+ | |||
+ | I still load evil with M-x, I didn't set (evil-mode 1), so in order to tweak keybindings I had to enclose them in a hook, so that my config is called when evil is called and not at startup: | ||
(add-hook 'evil-after-load-hook | (add-hook 'evil-after-load-hook | ||
Line 72: | Line 79: | ||
)) | )) | ||
− | + | == Hooks == | |
There are some hooks that allow to do things when we enter or exit a mode (see the pdf manual). | There are some hooks that allow to do things when we enter or exit a mode (see the pdf manual). | ||
Line 89: | Line 96: | ||
(add-hook 'evil-insert-state-exit-hook 'my-save-if-bufferfilename) | (add-hook 'evil-insert-state-exit-hook 'my-save-if-bufferfilename) | ||
− | + | == Enter an emacs mode in a given state == | |
There are some situations where you don't want to be in normal mode by default. For example, it's more useful to be in insert mode when we enter a magit commit buffer, or maybe you prefer to be in emacs mode in a dired buffer. | There are some situations where you don't want to be in normal mode by default. For example, it's more useful to be in insert mode when we enter a magit commit buffer, or maybe you prefer to be in emacs mode in a dired buffer. | ||
Line 121: | Line 128: | ||
</source> | </source> | ||
− | === Articles | + | = See also = |
+ | |||
+ | == Articles == | ||
* [http://dnquark.com/blog/2012/02/emacs-evil-ecumenicalism/ Emacs Evil Ecumenicalism] | * [http://dnquark.com/blog/2012/02/emacs-evil-ecumenicalism/ Emacs Evil Ecumenicalism] | ||
− | + | == Plug-ins == | |
* [[ace-jump]]: Port of Vim's Easy-motion: jump to any character in the buffer with 3 keystrokes. | * [[ace-jump]]: Port of Vim's Easy-motion: jump to any character in the buffer with 3 keystrokes. | ||
Line 135: | Line 144: | ||
* [https://github.com/cofi/evil-leader evil-leader]: Port of Vim's mapleader. | * [https://github.com/cofi/evil-leader evil-leader]: Port of Vim's mapleader. | ||
− | + | == Bug tracker == | |
The bugtrucker can be found on [https://bitbucket.org/lyro/evil/issues?status=new&status=open Bitbucket]. | The bugtrucker can be found on [https://bitbucket.org/lyro/evil/issues?status=new&status=open Bitbucket]. | ||
[[Category:Vi User]] [[Category:Vim User]] | [[Category:Vi User]] [[Category:Vim User]] |
Revision as of 11:13, 14 January 2014
Evil is an extensible vi layer for Emacs. It provides Vim features like Visual selection and text objects, and is the successor to the now defunct vimpulse and vim-mode.
Installation
Evil comes prebuilt in emacs24. In Emacs23, Evil can be downloaded and installed using el-get with: M-x el-get-install RET evil RET.
Manual install
Alternatively, Evil lives in a Git repository. To download Evil, do:
git clone git://gitorious.org/evil/evil.git
If you don't have Git, just head over to Gitorious and click the "Download master as tar.gz" link (extract with tar -xzf master.tar.gz).
If you installed it manually, move Evil to ~/.emacs.d/evil (or somewhere else in your load-path). In any case, add the following lines to ~/.emacs:
(add-to-list 'load-path "~/.emacs.d/evil") ;;no need with 24 (require 'evil) (evil-mode 1)
Evil requires UndoTree in the load-path for linear undo and undo branches. Otherwise, Evil uses regular Emacs undo.
Documentation
A brief PDF manual is available in the /doc subdirectory.
Configuration
One thing I would recommend to any ex vimmer is to make escape to quit actually pretty much anything (like pending prompts in the minibuffer):
;;; esc quits (define-key evil-normal-state-map [escape] 'keyboard-quit) (define-key evil-visual-state-map [escape] 'keyboard-quit) (define-key minibuffer-local-map [escape] 'minibuffer-keyboard-quit) (define-key minibuffer-local-ns-map [escape] 'minibuffer-keyboard-quit) (define-key minibuffer-local-completion-map [escape] 'minibuffer-keyboard-quit) (define-key minibuffer-local-must-match-map [escape] 'minibuffer-keyboard-quit) (define-key minibuffer-local-isearch-map [escape] 'minibuffer-keyboard-quit)
The following makes you loose vim commands, but gives you back basic emacs commands, like C-y to paste in insert mode or C-r to search backward:
(define-key evil-normal-state-map "\C-y" 'yank) (define-key evil-insert-state-map "\C-y" 'yank) (define-key evil-visual-state-map "\C-y" 'yank) (define-key evil-insert-state-map "\C-e" 'end-of-line) (define-key evil-normal-state-map "\C-w" 'evil-delete) (define-key evil-insert-state-map "\C-w" 'evil-delete) (define-key evil-insert-state-map "\C-r" 'search-backward) (define-key evil-visual-state-map "\C-w" 'evil-delete)
Use fine grain undo
In insert mode, Evil uses linear undo. If you want fine grain undo:
(setq evil-want-fine-undo t)
but remember, we shouldn't stay long in insert mode.
Use keychords to go back to normal mode
If you'd like to type jj or jk in insert mode to go back to normal mode, you may use key-chord:
(key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
Load config only when we call evil-mode
I still load evil with M-x, I didn't set (evil-mode 1), so in order to tweak keybindings I had to enclose them in a hook, so that my config is called when evil is called and not at startup:
(add-hook 'evil-after-load-hook (lambda () ;; config ))
Hooks
There are some hooks that allow to do things when we enter or exit a mode (see the pdf manual).
For example, to save the buffer when we exit the insert mode:
(defun my-save-if-bufferfilename () (if (buffer-file-name) (progn (save-buffer) ) (message "no file is associated to this buffer: do nothing") ) )
(add-hook 'evil-insert-state-exit-hook 'my-save-if-bufferfilename)
Enter an emacs mode in a given state
There are some situations where you don't want to be in normal mode by default. For example, it's more useful to be in insert mode when we enter a magit commit buffer, or maybe you prefer to be in emacs mode in a dired buffer.
For that purpose, evil provides the evil-set-initial-state command (see part 2.2 of the pdf documentation) that we can use like that:
(evil-set-initial-state 'git-commit-mode 'insert) ;; enter insert mode to edit a commit message
Here is a handy loop to define more at once:
(loop for (mode . state) in '((inferior-emacs-lisp-mode . emacs)
(nrepl-mode . insert)
(pylookup-mode . emacs)
(comint-mode . normal)
(shell-mode . insert)
(git-commit-mode . insert)
(git-rebase-mode . emacs)
(term-mode . emacs)
(help-mode . emacs)
(helm-grep-mode . emacs)
(grep-mode . emacs)
(bc-menu-mode . emacs)
(magit-branch-manager-mode . emacs)
(rdictcc-buffer-mode . emacs)
(dired-mode . emacs)
(wdired-mode . normal))
do (evil-set-initial-state mode state))
See also
Articles
Plug-ins
- ace-jump: Port of Vim's Easy-motion: jump to any character in the buffer with 3 keystrokes.
- evil-surround: Port of Vim's surround script.
- evil-numbers: Vim-like increment and decrement.
- evil-leader: Port of Vim's mapleader.
Bug tracker
The bugtrucker can be found on Bitbucket.