https://wikemacs.org/api.php?action=feedcontributions&user=149.254.183.248&feedformat=atomWikEmacs - User contributions [en]2024-03-28T15:59:04ZUser contributionsMediaWiki 1.35.14https://wikemacs.org/index.php?title=Evil&diff=46657Evil2014-05-16T14:53:57Z<p>149.254.183.248: Lose instead of loose</p>
<hr />
<div>'''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.<br />
<br />
= Installation =<br />
<br />
Evil comes prebuilt in emacs24. <br />
In Emacs23, Evil can be downloaded and installed using [[el-get]] with: {{Command|el-get-install RET evil RET}}.<br />
<br />
<br />
<br />
== Manual install ==<br />
<br />
<br />
Alternatively, Evil lives in a Git repository. To download Evil, do:<br />
<br />
git clone git://gitorious.org/evil/evil.git<br />
<br />
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).<br />
<br />
If you installed it manually, move Evil to {{Filename|~/.emacs.d/evil}} (or somewhere else in your load-path). <br />
In any case, add the following lines to ~/.emacs:<br />
<br />
(add-to-list 'load-path "~/.emacs.d/evil") ;;no need with 24<br />
(require 'evil)<br />
(evil-mode 1)<br />
<br />
<br />
Evil requires [[UndoTree]] in the load-path for linear undo and undo branches. Otherwise, Evil uses regular Emacs undo.<br />
<br />
= Documentation =<br />
<br />
A brief [https://gitorious.org/evil/evil/blobs/raw/doc/doc/evil.pdf PDF manual] is available in the /doc subdirectory.<br />
<br />
= Usage =<br />
<br />
For those not familiar with vim, here's a quick summary of useful commands.<br />
<br />
<br />
'''Tip:''': to see a full list of commands available in the current mode, install ''help-fns+'' with [[ELPA]], require it (see its doc). Now you can type '''C-h M-k'''.<br />
<br />
<br />
To enter '''insert''' state: try out '''i a o''' and the upper-case ones;<br />
<br />
To delete chars, words and lines use '''x''', the usual '''d''' followed by a word or a movement ('''$''' is end of line, '''^''' the beginning), '''dd''' and '''D''', or replace an object with '''c''' ;<br />
<br />
Copy and paste: '''y Y p P''' ;<br />
<br />
To navigate around the buffer, in normal mode, use '''e E w W b B t T f F ( ) { }''' and '''j k h l - + <RET> <backspace> <space>'''; <br />
Go to beginning and end of buffer with '''gg''' and '''G'''; <br />
<br />
Cycle between cursor position: double backquotes, '''C-i''' and '''C-o''';<br />
<br />
To navigate around the screen, use '''H L M''' to go to the Highest/Lowest/Middle line of the screen;<br />
<br />
Search forward and backward with '''/''' and '''?''', use '''n''' and '''N''' to go to the next and previous occurence;<br />
<br />
Go to the next or previous occurence of token under point with '''*''' or '''#''' ;<br />
<br />
Select a region with '''v''' or '''V''' and re-select the last region selected with '''gv''' ;<br />
<br />
Go to the '''definition of the symbol''' under point with '''gd''' ;<br />
<br />
Indent the line or region with '''<''' and '''>''' ;<br />
<br />
<br />
Some more:<br />
<br />
Join lines with '''J''' <br />
<br />
Set a mark with '''m<char>''', go to a mark with backquote + <char><br />
<br />
'''Code folding''' with '''za''' (toggle), '''zc''' (close), '''zm''' and '''zr''' (close and open all)<br />
<br />
Move the current line at the center, bottom and top of screen: '''zz''', '''zb''' and '''zt''' (C-l with emacs)<br />
<br />
= Configuration =<br />
<br />
<br />
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):<br />
<br />
;;; esc quits<br />
(define-key evil-normal-state-map [escape] 'keyboard-quit)<br />
(define-key evil-visual-state-map [escape] 'keyboard-quit)<br />
(define-key minibuffer-local-map [escape] 'minibuffer-keyboard-quit)<br />
(define-key minibuffer-local-ns-map [escape] 'minibuffer-keyboard-quit)<br />
(define-key minibuffer-local-completion-map [escape] 'minibuffer-keyboard-quit)<br />
(define-key minibuffer-local-must-match-map [escape] 'minibuffer-keyboard-quit)<br />
(define-key minibuffer-local-isearch-map [escape] 'minibuffer-keyboard-quit)<br />
<br />
The following makes you lose vim commands, but gives you back basic emacs commands, like C-y to paste in insert mode or C-r to search backward:<br />
<br />
(define-key evil-normal-state-map "\C-y" 'yank)<br />
(define-key evil-insert-state-map "\C-y" 'yank)<br />
(define-key evil-visual-state-map "\C-y" 'yank)<br />
(define-key evil-insert-state-map "\C-e" 'end-of-line)<br />
(define-key evil-normal-state-map "\C-w" 'evil-delete)<br />
(define-key evil-insert-state-map "\C-w" 'evil-delete)<br />
(define-key evil-insert-state-map "\C-r" 'search-backward)<br />
(define-key evil-visual-state-map "\C-w" 'evil-delete)<br />
<br />
== Use fine grain undo ==<br />
<br />
In insert mode, Evil uses linear undo. If you want fine grain undo:<br />
<br />
(setq evil-want-fine-undo t)<br />
<br />
but remember, we shouldn't stay long in insert mode.<br />
<br />
== Use keychords to go back to normal mode ==<br />
<br />
If you'd like to type jj or jk in insert mode to go back to normal mode, you may use [[key-chord]]:<br />
<br />
(key-chord-define evil-insert-state-map "jj" 'evil-normal-state)<br />
<br />
== Load config only when we call evil-mode ==<br />
<br />
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:<br />
<br />
(add-hook 'evil-after-load-hook<br />
(lambda ()<br />
;; config<br />
))<br />
<br />
== Hooks ==<br />
<br />
There are some hooks that allow to do things when we enter or exit a mode (see the pdf manual).<br />
<br />
For example, to save the buffer when we exit the insert mode:<br />
<br />
(defun my-save-if-bufferfilename ()<br />
(if (buffer-file-name)<br />
(progn<br />
(save-buffer)<br />
)<br />
(message "no file is associated to this buffer: do nothing")<br />
)<br />
)<br />
<br />
(add-hook 'evil-insert-state-exit-hook 'my-save-if-bufferfilename)<br />
<br />
== Enter an emacs mode in a given state ==<br />
<br />
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.<br />
<br />
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:<br />
<br />
<source lang="lisp"><br />
(evil-set-initial-state 'git-commit-mode 'insert) ;; enter insert mode to edit a commit message<br />
</source><br />
<br />
Here is a handy loop to define more at once:<br />
<br />
<source lang="lisp"><br />
(loop for (mode . state) in '((inferior-emacs-lisp-mode . emacs)<br />
(nrepl-mode . insert)<br />
(pylookup-mode . emacs)<br />
(comint-mode . normal)<br />
(shell-mode . insert)<br />
(git-commit-mode . insert)<br />
(git-rebase-mode . emacs)<br />
(term-mode . emacs)<br />
(help-mode . emacs)<br />
(helm-grep-mode . emacs)<br />
(grep-mode . emacs)<br />
(bc-menu-mode . emacs)<br />
(magit-branch-manager-mode . emacs)<br />
(rdictcc-buffer-mode . emacs)<br />
(dired-mode . emacs)<br />
(wdired-mode . normal))<br />
do (evil-set-initial-state mode state))<br />
</source><br />
<br />
= See also =<br />
<br />
== Articles ==<br />
<br />
* [http://dnquark.com/blog/2012/02/emacs-evil-ecumenicalism/ Emacs Evil Ecumenicalism]<br />
<br />
== Plug-ins ==<br />
<br />
* [[ace-jump]]: Port of Vim's Easy-motion: jump to any character in the buffer with 3 keystrokes.<br />
<br />
* [https://github.com/timcharper/evil-surround evil-surround]: Port of Vim's surround script.<br />
<br />
* [https://github.com/cofi/evil-numbers evil-numbers]: Vim-like increment and decrement.<br />
<br />
* [https://github.com/cofi/evil-leader evil-leader]: Port of Vim's mapleader.<br />
<br />
== Bug tracker ==<br />
<br />
The bugtrucker can be found on [https://bitbucket.org/lyro/evil/issues?status=new&status=open Bitbucket].<br />
[[Category:Vi User]] [[Category:Vim User]]</div>149.254.183.248