Evil-Tutor
2024-01-31 Note evil manual notes배울게 많다. 이 마저도 모르고 사용했다면 반성해야 한다.
dw - delete word d$ - delete line
[number] d object or d [number] object
object ? w : word, e : word w/o space, $ : line
Introduction
=============================================================================
= W e l c o m e t o t h e E m a c s E v i l T u t o r = = = = * * * = = = = Version 1.0 = =============================================================================
TL;DR: press C-j (CTRL+j) to jump right to the first lesson. The tutorial takes approximately 30 minutes.
At any moment if you feel stuck, you can switch to emacs state with:
M-x evil-emacs-state RET
Then continue the tutorial by going back to the normal state with:
M-x evil-normal-state RET
- * *
Evil is a very powerful emulation of Vim that has many commands, too many to explain in a tutor such as this. This tutor is designed to describe enough of the commands that you will be able to easily use Emacs powered with Evil as an all-purpose editor.
The approximate time required to complete the tutor is 25-30 minutes, depending upon how much time is spent with experimentation.
The commands in the lessons will modify the text. Make a copy of this file to practise on (if you started “evil-tutor-mode” this is already a copy).
It is important to remember that this tutor is set up to teach by use. That means that you need to execute the commands to learn them properly. If you only read the text, you will forget the commands!
Now, make sure that your Shift-Lock key is NOT depressed and press the j key enough times to move the cursor so that Lesson 1.1 completely fills the screen.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1.1: MOVING THE CURSOR
* To move the cursor, press the h,j,k,l keys as indicated. * ^ k Hint: The h key is at the left and moves left. < h l > The l key is at the right and moves right. j The j key looks like a down arrow v
Move the cursor around the screen until you are comfortable.
Hold down the down key (j) until it repeats.
—> Now you know how to move to the next lesson
- Using the down key, move to Lesson 1.2.
Note: If you are ever unsure about something you typed, press <ESC> to place you in normal state. Then retype the command you wanted.
Note: The cursor keys should also work. But using hjkl you will be able to move around much faster, once you get used to it.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1.2: ENTERING AND EXITING EMACS
!! NOTE: Before executing any of the steps below, read this entire lesson!!
Press the <ESC> key (to make sure you are in normal state).
Type: :qa! <ENTER>.
—> This exits the editor WITHOUT saving any changes you have made. If you want to save the changes and exit type: :wqa <ENTER>
When you see the shell prompt, return in Emacs and resume your tutorial session by typing: M-x evil-tutor-start
If you have these steps memorized and are confident, execute steps 1 through 3 to exit and re-enter the editor. Then move the cursor down to Lesson 1.3.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1.3: TEXT EDITING - DELETION
While in normal state press x to delete the character under the cursor. **
Move the cursor to the line below marked —>.
To fix the errors, move the cursor until it is on top of the character to be deleted.
Press the x key to delete the unwanted character.
Repeat steps 2 through 4 until the sentence is correct.
—> The ccow jumpedd ovverr thhe mooon.
- Now that the line is correct, go on to Lesson 1.4.
NOTE: As you go through this tutor, do not try to memorize, learn by usage.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1.4: TEXT EDITING - INSERTION
* While in normal state press i to insert text. *
Move the cursor to the first line below marked —>.
To make the first line the same as the second, move the cursor on top of the first character AFTER where the text is to be inserted.
Press i and type in the necessary additions.
As each error is fixed press <ESC> to return to normal state. Repeat steps 2 through 4 to correct the sentence.
—> There is text misng this . —> There is some text missing from this line.
- When you are comfortable inserting text move to the summary below.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LESSON 1 SUMMARY
The cursor is moved using either the arrow keys or the hjkl keys. h (left) j (down) k (up) l (right)
To exit Emacs type: <ESC> :qa! <ENTER> to trash all changes. OR type: <ESC> :wqa <ENTER> to save the changes.
To delete a character under the cursor in normal state type: x
To insert text at the cursor while in normal state type: i type in text <ESC>
NOTE: Pressing <ESC> will place you in normal state or will cancel an unwanted and partially completed command.
Now continue with Lesson 2.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1: DELETION COMMANDS
* Type dw to delete to the end of a word. *
Press <ESC> to make sure you are in normal state.
Move the cursor to the line below marked —>.
Move the cursor to the beginning of a word that needs to be deleted.
Type dw to make the word disappear.
NOTE: The letters dw will appear on the last line of the screen as you type them. If you typed something wrong, press <ESC> and start over.
—> There are a some words fun that don’t belong paper in this sentence.
- Repeat steps 3 and 4 until the sentence is correct and go to Lesson 2.2.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.2: MORE DELETION COMMANDS
* Type d$ to delete to the end of the line. *
Press <ESC> to make sure you are in normal state.
Move the cursor to the line below marked —>.
Move the cursor to the end of the correct line (AFTER the first . ).
Type d$ to delete to the end of the line.
—> Somebody typed the end of this line twice. end of this line twice.
- Move on to Lesson 2.3 to understand what is happening.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.3: ON COMMANDS AND OBJECTS
The format for the d delete command is as follows:
[number] d object OR d [number] object
Where: number - is how many times to execute the command (optional, default=1). d - is the command to delete. object - is what the command will operate on (listed below).
A short list of objects: w - from the cursor to the end of the word, including the space. e - from the cursor to the end of the word, NOT including the space. $ - from the cursor to the end of the line.
NOTE: For the adventurous, pressing just the object while in normal state without a command will move the cursor as specified in the object list.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.4: AN EXCEPTION TO ‘COMMAND-OBJECT’
Type dd to delete a whole line.
Due to the frequency of whole line deletion, the designers of Evil (credits to designers of Vim) decided it would be easier to simply type two d’s in a row to delete a line.
전체 줄 삭제가 빈번하게 발생하기 때문에 Evil 의 디자이너(Vim 의 디자이너에게 크레딧이 돌아감)는 한 줄을 삭제하려면 단순히 두 개의 d 를 연속으로 입력하는 것이 더 쉬울 것이라고 판단했습니다.
- Move the cursor to the second line in the phrase below.
- Type dd to delete the line.
- Now move to the fourth line.
- Type 2dd (remember number-command-object) to delete the two lines.
- Roses are red,
- Mud is fun,
- Violets are blue,
- I have a car,
- Clocks tell time,
- Sugar is sweet
- And so are you.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.5: THE UNDO COMMAND
* Press u to undo the last commands *
- Move the cursor to the line below marked —> and place it on the first error.
- Type x to delete the first unwanted character.
- Now type u to undo the last command executed.
- This time fix all the errors on the line using the x command.
- Now type u a few times to undo all the preceding commands.
- Now type CTRL-R (keeping CTRL key pressed while hitting R) a few times to redo the commands (undo the undo’s).
—> Fiix the errors oon thhis line and reeplace them witth undo.
- These are very useful commands. Now move on to the Lesson 2 Summary.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LESSON 2 SUMMARY
To delete from the cursor to the end of a word type: dw
To delete from the cursor to the end of a line type: d$
To delete a whole line type: dd
The format for a command in normal state is:
[number] command object OR command [number] object where: number - is how many times to repeat the command command - is what to do, such as d for delete object - is what the command should act upon, such as w for word, $ for “to the end of line”, etc.
To undo previous actions, type: u To undo the undo’s type: CTRL-R
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 3.1: THE PUT COMMAND
* Type p to put the last deletion after the cursor. *
Move the cursor to the first line in the set below.
Type dd to delete the line and store it in Emacs’s kill ring.
Move the cursor to the line ABOVE where the deleted line should go.
While in normal state, type p to replace the line.
Repeat steps 2 through 4 to put all the lines in correct order.
- Can you learn too?
- Violets are blue,
- Intelligence is learned,
- Roses are red,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 3.2: THE REPLACE COMMAND
* Type r and a character to replace the character under the cursor. *
Move the cursor to the first line below marked —>.
Move the cursor so that it is on top of the first error.
Type r and then the character which should replace the error.
Repeat steps 2 and 3 until the first line is correct.
—> Whan this lime was tuoed in, someone presswd some wrojg keys! —> When this line was typed in, someone pressed some wrong keys!
- Now move on to Lesson 3.2.
NOTE: Remember that you should be learning by use, not memorization.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 3.3: THE CHANGE COMMAND
* To change part or all of a word, type cw *
Move the cursor to the first line below marked —>.
Place the cursor on the u in lubw.
Type cw and the correct word (in this case, type ‘ine’.)
Press <ESC> and move to the next error (the first character to be changed.)
Repeat steps 3 and 4 until the first sentence is the same as the second.
—> This line has a few words that mrrf changing usf the change command. —> This line has a few words that need changing using the change command.
Notice that cw not only replaces the word, but also places you in insert.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 3.4: MORE CHANGES USING c
* The change command is used with the same objects as delete. *
The change command works in the same way as delete. The format is:
[number] c object OR c [number] object
The objects are also the same, such as w (word), $ (end of line) etc…
Move to the first line below marked —>.
Move the cursor to the first error.
Type c$ to make the rest of the line like the second and press <ESC>.
—> The end of this line needs some help to make it like the second. —> The end of this line needs to be corrected using the c$ command.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LESSON 3 SUMMARY
To replace text that has already been deleted, type
p
this puts the deleted text AFTER the cursor (if a line was deleted it will go on the line below the cursor).To replace the character under the cursor, type
r
and then the character which will replace the original.The change command allows you to change the specified object from the cursor to the end of the object. eg. Type
cw
to change from the cursor to the end of the word, c$ to change to the end of a line.The format for change is:
[number] c object OR c [number] object
Now go on to the next lesson.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.1: FAST MOVE IN A BUFFER
* Type gg
to go to the beginning of a buffer. Type G
to move to the end of a buffer. *
Note: Read this entire lesson before executing any of the steps!!
Remember the current line number where you are for Step 4.
Press G to move you to the bottom of the buffer.
Press gg to move you to the beginning of the buffer.
Type : and the number of the line you were on and then <ENTER> .This will return you to the line you were on before the step 2.
If you feel confident to do this, execute steps 1 through 3.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.2: THE SEARCH COMMAND
* Type / followed by a phrase to search for the phrase. *
In normal state type the / character. Notice that it and the cursor appear at the bottom of the screen as with the : command.
Now type ’errroor’ <ENTER>. This is the word you want to search for.
To search for the same phrase again, simply type: n To search for the same phrase in the opposite direction, type: N
If you want to search for a phrase in the backwards direction, use the command ? instead of /
—> When the search reaches the end of the buffer it will continue at the start.
“errroor” is not the way to spell error; errroor is an error.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.3: MATCHING PARENTHESES SEARCH
* Type % to find a matching ),], or } *
Place the cursor on any (, [, or { in the line below marked —>.
Now type the % character.
The cursor should be on the matching parenthesis or bracket.
Type % to move the cursor back to the first bracket (by matching).
—> This ( is a test line with (’s, [’s ] and {’s } in it. ))
Note: This is very useful in debugging a program with unmatched parentheses (and in elisp)!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.4: A WAY TO CHANGE ERRORS
* Type :s/old/new/g to substitute ’new’ for ‘old’. *
Move the cursor to the line below marked —>.
Type :s/thee/the <ENTER> Note that this command only changes the first occurrence on the line.
Now type :s/thee/the/g meaning substitute globally on the line. This changes all occurrences on the line.
—> thee best time to see thee flowers is in thee spring.
To change every occurrence of a character string between two lines,
type :#,#s/old/new/g where #,# are the numbers of the two lines.
Type :%s/old/new/g to change every occurrence in the whole buffer.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LESSON 4 SUMMARY
gg moves to the beginning of the buffer. G moves to the end of the buffer.
followed by a line number then <ENTER> moves to that line number.
Typing / followed by a phrase searches FORWARD for the phrase. Typing ? followed by a phrase searches BACKWARD for the phrase. After a search type n to find the next occurrence in the same direction or N to search in the opposite direction.
Typing % while the cursor is on a (,),[,],{, or } locates its matching pair.
To substitute new for the first old on a line type :s/old/new To substitute new for all ‘old’s on a line type :s/old/new/g To substitute phrases between two line #’s type :#,#s/old/new/g To substitute all occurrences in the file type :%s/old/new/g To ask for confirmation each time add ‘c’ :%s/old/new/gc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.1: HOW TO EXECUTE AN EXTERNAL COMMAND
* Type :! followed by an external command to execute that command. *
Type the familiar command : to set the cursor at the bottom of the screen. This allows you to enter a command (remember we already used this to go to a line number in a buffer).
Now type the ! (exclamation point) character. This allows you to execute any external shell command.
As an example type ls following the ! and then hit <ENTER>. This will show you a listing of your directory, just as if you were at the shell prompt. Or use :!dir if ls doesn’t work (on Windows).
—> Note: It is possible to execute any external command this way.
—> Note: All : commands must be finished by hitting <ENTER>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.2: MORE ON WRITING FILES
* To save the changes made to the file, type :w FILENAME *
Type :!ls or :!dir to get a listing of your directory. You already know you must hit <ENTER> after this.
Choose a filename that does not exist yet, such as TEST.
Now type: :w TEST (where TEST is the filename you chose.)
This saves the whole file under the name TEST. To verify this, type :!ls or :!dir again to see your directory
—> Note that if you were to exit Emacs and enter again with the filename TEST, the file would be an exact copy of the tutor when you saved it.
- Now remove the file by typing: on Unix: :!rm TEST on Windows: :!del TEST
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.3: A SELECTIVE WRITE COMMAND
* To save part of the file, type :#,# w FILENAME *
Once again, type :!ls or :!dir to obtain a listing of your directory and choose a suitable filename such as TEST.
Move the cursor to the top of this lesson by pressing C-k to find the number of that line. REMEMBER THIS NUMBER!
Now move to the bottom of the lesson by pressing C-j to find the number of that line. REMEMBER THIS LINE NUMBER ALSO!
To save ONLY a section to a file, type :#,# w TEST where #,# are the two numbers you remembered (top,bottom) and TEST is your filename.
Again, see that the file is there with :!ls or :!dir but DO NOT remove it.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.4: RETRIEVING AND MERGING FILES
* To insert the contents of a file, type :r FILENAME *
Type :!ls or :!dir to make sure your TEST filename is present from before.
Place the cursor at the top of this lesson.
NOTE: After executing Step 3 you will see Lesson 5.3. Then move DOWN to this lesson again.
- Now retrieve your TEST file using the command :r TEST where TEST is the name of the file.
NOTE: The file you retrieve is placed starting where the cursor is located.
- To verify that a file was retrieved, cursor back and notice that there are now two copies of Lesson 5.3, the original and the file version.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LESSON 5 SUMMARY
:!command executes an external command.
Some useful examples are: :!ls or :!dir - shows a directory listing. :!rm or :!del FILENAME - removes file FILENAME.
:w FILENAME writes the current buffer to disk with file name FILENAME.
:#,#w FILENAME saves the lines # through # in file FILENAME.
:r FILENAME retrieves disk file FILENAME and inserts it into the current buffer following the cursor position.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.1: THE OPEN COMMAND
* Type o to open a line below the cursor and place you in insert state. *
Move the cursor to the line below marked —>.
Type o to open up a line BELOW the cursor and place you in insert state
Now copy the line marked —> and press <ESC> to exit insert state.
—> After typing o the cursor is placed on the open line in insert state.
- To open up a line ABOVE the cursor, simply type a capital O rather than a lowercase o Try this on the line below.
Open up a line above this by typing O while the cursor is on this line.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.2: THE APPEND COMMAND
* Type a to insert text AFTER the cursor. *
Move the cursor to the end of the first line below marked —> by typing $ in normal state.
Type an a to append text AFTER the character under the cursor. (Uppercase A appends to the end of the line.)
Note: This avoids typing i , the last character, the text to insert, <ESC>, cursor-right, and finally, x , just to append to the end of a line!
- Now complete the first line. Note also that append is exactly the same as insert state, except for the location where text is inserted.
—> This line will allow you to practice —> This line will allow you to practice appending text to the end of a line.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.3: ANOTHER VERSION OF REPLACE
* Type a capital R to replace more than one character. *
Move the cursor to the first line below marked —>.
Place the cursor at the beginning of the first word that is different from the second line marked —> (the word ’last’).
Now type R and replace the remainder of the text on the first line by typing over the old text to make the first line the same as the second.
—> To make the first line the same as the last on this page use the keys. —> To make the first line the same as the second, type R and the new text.
- Note that when you press <ESC> to exit, any unaltered text remains.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LESSON 6 SUMMARY
Typing o opens a line BELOW the cursor and places the cursor on the open line in insert state. Typing a capital O opens the line ABOVE the line the cursor is on.
Type an a to insert text AFTER the character the cursor is on. Typing a capital A automatically appends text to the end of the line.
Typing a capital R enters Replace mode until <ESC> is pressed to exit.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This concludes the Evil Tutor. It was intended to give a brief overview of Emacs+Evil editor, just enough to allow you to use the editor fairly easily. It is far from complete as Evil has many many more commands.
This tutorial was written by Michael C. Pierce and Robert K. Ware, Colorado School of Mines using ideas supplied by Charles Smith, Colorado State University. E-mail: bware@mines.colorado.edu.
Modified for Vim by Bram Moolenaar. Modified for Emacs+Evil by Sylvain Benner.
Based on vimtutor 1.5
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~