blob: 5d1483c06f6be5a550e320a40753db96783a9504 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001===============================================================================
Bram Moolenaar843ee412004-06-30 16:16:41 +00002= W e l c o m e t o t h e V I M T u t o r - Version 1.7 =
Bram Moolenaar071d4272004-06-13 20:20:40 +00003===============================================================================
RestorerZ6fa304f2024-12-02 20:19:52 +01004= C H A P T E R ONE =
5===============================================================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
7 Vim is a very powerful editor that has many commands, too many to
8 explain in a tutor such as this. This tutor is designed to describe
9 enough of the commands that you will be able to easily use Vim as
10 an all-purpose editor.
Bram Moolenaard1caa942020-04-10 22:10:56 +020011 The approximate time required to complete the tutor is 30 minutes,
Bram Moolenaar071d4272004-06-13 20:20:40 +000012 depending upon how much time is spent with experimentation.
13
Bram Moolenaar843ee412004-06-30 16:16:41 +000014 ATTENTION:
Bram Moolenaar071d4272004-06-13 20:20:40 +000015 The commands in the lessons will modify the text. Make a copy of this
Bram Moolenaar37c64c72017-09-19 22:06:03 +020016 file to practice on (if you started "vimtutor" this is already a copy).
Bram Moolenaar071d4272004-06-13 20:20:40 +000017
18 It is important to remember that this tutor is set up to teach by
19 use. That means that you need to execute the commands to learn them
20 properly. If you only read the text, you will forget the commands!
Bram Moolenaar72540672018-02-09 22:00:53 +010021 Now, make sure that your Caps-Lock key is NOT depressed and press
Bram Moolenaar6dc819b2018-07-03 16:42:19 +020022 the j key enough times to move the cursor so that lesson 1.1
Bram Moolenaar071d4272004-06-13 20:20:40 +000023 completely fills the screen.
RestorerZ6fa304f2024-12-02 20:19:52 +010024
Bram Moolenaar071d4272004-06-13 20:20:40 +000025~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +010026 Lesson 1.1.1: MOVING THE CURSOR
Bram Moolenaar071d4272004-06-13 20:20:40 +000027
28
29 ** To move the cursor, press the h,j,k,l keys as indicated. **
30 ^
31 k Hint: The h key is at the left and moves left.
32 < h l > The l key is at the right and moves right.
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000033 j The j key looks like a down arrow.
Bram Moolenaar071d4272004-06-13 20:20:40 +000034 v
35 1. Move the cursor around the screen until you are comfortable.
36
37 2. Hold down the down key (j) until it repeats.
Bram Moolenaar843ee412004-06-30 16:16:41 +000038 Now you know how to move to the next lesson.
Bram Moolenaar071d4272004-06-13 20:20:40 +000039
RestorerZ6fa304f2024-12-02 20:19:52 +010040 3. Using the down key, move to lesson 1.1.2.
Bram Moolenaar071d4272004-06-13 20:20:40 +000041
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000042NOTE: If you are ever unsure about something you typed, press <ESC> to place
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 you in Normal mode. Then retype the command you wanted.
44
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000045NOTE: The cursor keys should also work. But using hjkl you will be able to
Bram Moolenaar843ee412004-06-30 16:16:41 +000046 move around much faster, once you get used to it. Really!
Bram Moolenaar071d4272004-06-13 20:20:40 +000047
48~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +010049 Lesson 1.1.2: EXITING VIM
Bram Moolenaar071d4272004-06-13 20:20:40 +000050
51
52 !! NOTE: Before executing any of the steps below, read this entire lesson!!
53
54 1. Press the <ESC> key (to make sure you are in Normal mode).
55
Bram Moolenaar843ee412004-06-30 16:16:41 +000056 2. Type: :q! <ENTER>.
57 This exits the editor, DISCARDING any changes you have made.
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
Bram Moolenaardfb18412013-12-11 18:53:29 +010059 3. Get back here by executing the command that got you into this tutor. That
60 might be: vimtutor <ENTER>
Bram Moolenaar071d4272004-06-13 20:20:40 +000061
62 4. If you have these steps memorized and are confident, execute steps
Bram Moolenaar843ee412004-06-30 16:16:41 +000063 1 through 3 to exit and re-enter the editor.
64
65NOTE: :q! <ENTER> discards any changes you made. In a few lessons you
66 will learn how to save the changes to a file.
67
RestorerZ6fa304f2024-12-02 20:19:52 +010068 5. Move the cursor down to lesson 1.1.3.
Bram Moolenaar843ee412004-06-30 16:16:41 +000069
70
Bram Moolenaar071d4272004-06-13 20:20:40 +000071~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +010072 Lesson 1.1.3: TEXT EDITING - DELETION
Bram Moolenaar071d4272004-06-13 20:20:40 +000073
74
Bram Moolenaar843ee412004-06-30 16:16:41 +000075 ** Press x to delete the character under the cursor. **
Bram Moolenaar071d4272004-06-13 20:20:40 +000076
77 1. Move the cursor to the line below marked --->.
78
79 2. To fix the errors, move the cursor until it is on top of the
80 character to be deleted.
81
82 3. Press the x key to delete the unwanted character.
83
84 4. Repeat steps 2 through 4 until the sentence is correct.
85
86---> The ccow jumpedd ovverr thhe mooon.
87
RestorerZ6fa304f2024-12-02 20:19:52 +010088 5. Now that the line is correct, go on to lesson 1.1.4.
Bram Moolenaar071d4272004-06-13 20:20:40 +000089
90NOTE: As you go through this tutor, do not try to memorize, learn by usage.
91
92
93
94~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +010095 Lesson 1.1.4: TEXT EDITING - INSERTION
Bram Moolenaar071d4272004-06-13 20:20:40 +000096
97
Bram Moolenaar843ee412004-06-30 16:16:41 +000098 ** Press i to insert text. **
Bram Moolenaar071d4272004-06-13 20:20:40 +000099
100 1. Move the cursor to the first line below marked --->.
101
102 2. To make the first line the same as the second, move the cursor on top
Bram Moolenaar4c92e752019-02-17 21:18:32 +0100103 of the character BEFORE which the text is to be inserted.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104
105 3. Press i and type in the necessary additions.
106
107 4. As each error is fixed press <ESC> to return to Normal mode.
108 Repeat steps 2 through 4 to correct the sentence.
109
110---> There is text misng this .
111---> There is some text missing from this line.
112
RestorerZ6fa304f2024-12-02 20:19:52 +0100113 5. When you are comfortable inserting text move to lesson 1.1.5.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000114
115
116
117~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100118 Lesson 1.1.5: TEXT EDITING - APPENDING
Bram Moolenaar843ee412004-06-30 16:16:41 +0000119
120
121 ** Press A to append text. **
122
123 1. Move the cursor to the first line below marked --->.
124 It does not matter on what character the cursor is in that line.
125
126 2. Press A and type in the necessary additions.
127
128 3. As the text has been appended press <ESC> to return to Normal mode.
129
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200130 4. Move the cursor to the second line marked ---> and repeat
Bram Moolenaar843ee412004-06-30 16:16:41 +0000131 steps 2 and 3 to correct this sentence.
132
133---> There is some text missing from th
134 There is some text missing from this line.
135---> There is also some text miss
136 There is also some text missing here.
137
RestorerZ6fa304f2024-12-02 20:19:52 +0100138 5. When you are comfortable appending text move to lesson 1.1.6.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000139
140~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100141 Lesson 1.1.6: EDITING A FILE
Bram Moolenaar843ee412004-06-30 16:16:41 +0000142
Bram Moolenaar843ee412004-06-30 16:16:41 +0000143 ** Use :wq to save a file and exit. **
144
145 !! NOTE: Before executing any of the steps below, read this entire lesson!!
146
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200147 1. If you have access to another terminal, do the following there.
RestorerZ6fa304f2024-12-02 20:19:52 +0100148 Otherwise, exit this tutor as you did in lesson 1.1.2: :q!
Bram Moolenaar843ee412004-06-30 16:16:41 +0000149
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200150 2. At the shell prompt type this command: vim file.txt <ENTER>
151 'vim' is the command to start the Vim editor, 'file.txt' is the name of
152 the file you wish to edit. Use the name of a file that you can change.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000153
154 3. Insert and delete text as you learned in the previous lessons.
155
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200156 4. Save the file with changes and exit Vim with: :wq <ENTER>
Bram Moolenaar843ee412004-06-30 16:16:41 +0000157
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +0000158 5. If you have quit vimtutor in step 1 restart the vimtutor and move down to
159 the following summary.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000160
161 6. After reading the above steps and understanding them: do it.
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200162
Bram Moolenaar843ee412004-06-30 16:16:41 +0000163~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100164 Lesson 1.1 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165
166
167 1. The cursor is moved using either the arrow keys or the hjkl keys.
168 h (left) j (down) k (up) l (right)
169
Bram Moolenaar843ee412004-06-30 16:16:41 +0000170 2. To start Vim from the shell prompt type: vim FILENAME <ENTER>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171
172 3. To exit Vim type: <ESC> :q! <ENTER> to trash all changes.
173 OR type: <ESC> :wq <ENTER> to save the changes.
174
Bram Moolenaar843ee412004-06-30 16:16:41 +0000175 4. To delete the character at the cursor type: x
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176
Bram Moolenaar843ee412004-06-30 16:16:41 +0000177 5. To insert or append text type:
178 i type inserted text <ESC> insert before the cursor
179 A type appended text <ESC> append after the line
Bram Moolenaar071d4272004-06-13 20:20:40 +0000180
181NOTE: Pressing <ESC> will place you in Normal mode or will cancel
182 an unwanted and partially completed command.
183
RestorerZ6fa304f2024-12-02 20:19:52 +0100184Now continue with lesson 1.2.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000185
Bram Moolenaar071d4272004-06-13 20:20:40 +0000186~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100187 Lesson 1.2.1: DELETION COMMANDS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000188
189
Bram Moolenaar843ee412004-06-30 16:16:41 +0000190 ** Type dw to delete a word. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000191
192 1. Press <ESC> to make sure you are in Normal mode.
193
194 2. Move the cursor to the line below marked --->.
195
196 3. Move the cursor to the beginning of a word that needs to be deleted.
197
198 4. Type dw to make the word disappear.
199
Bram Moolenaar843ee412004-06-30 16:16:41 +0000200 NOTE: The letter d will appear on the last line of the screen as you type
201 it. Vim is waiting for you to type w . If you see another character
202 than d you typed something wrong; press <ESC> and start over.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000203
204---> There are a some words fun that don't belong paper in this sentence.
205
RestorerZ6fa304f2024-12-02 20:19:52 +0100206 5. Repeat steps 3 and 4 until the sentence is correct and go to lesson 1.2.2.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000207
208
Bram Moolenaar071d4272004-06-13 20:20:40 +0000209~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100210 Lesson 1.2.2: MORE DELETION COMMANDS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000211
212
213 ** Type d$ to delete to the end of the line. **
214
215 1. Press <ESC> to make sure you are in Normal mode.
216
217 2. Move the cursor to the line below marked --->.
218
219 3. Move the cursor to the end of the correct line (AFTER the first . ).
220
221 4. Type d$ to delete to the end of the line.
222
223---> Somebody typed the end of this line twice. end of this line twice.
224
225
RestorerZ6fa304f2024-12-02 20:19:52 +0100226 5. Move on to lesson 1.2.3 to understand what is happening.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000227
228
229
230
231
232~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100233 Lesson 1.2.3: ON OPERATORS AND MOTIONS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000234
235
Bram Moolenaar843ee412004-06-30 16:16:41 +0000236 Many commands that change text are made from an operator and a motion.
237 The format for a delete command with the d delete operator is as follows:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238
Bram Moolenaar843ee412004-06-30 16:16:41 +0000239 d motion
240
Bram Moolenaar071d4272004-06-13 20:20:40 +0000241 Where:
Bram Moolenaar843ee412004-06-30 16:16:41 +0000242 d - is the delete operator.
243 motion - is what the operator will operate on (listed below).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244
Bram Moolenaar843ee412004-06-30 16:16:41 +0000245 A short list of motions:
246 w - until the start of the next word, EXCLUDING its first character.
247 e - to the end of the current word, INCLUDING the last character.
248 $ - to the end of the line, INCLUDING the last character.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000249
Bram Moolenaar843ee412004-06-30 16:16:41 +0000250 Thus typing de will delete from the cursor to the end of the word.
251
252NOTE: Pressing just the motion while in Normal mode without an operator will
253 move the cursor as specified.
254
255~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100256 Lesson 1.2.4: USING A COUNT FOR A MOTION
Bram Moolenaar843ee412004-06-30 16:16:41 +0000257
258
259 ** Typing a number before a motion repeats it that many times. **
260
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200261 1. Move the cursor to the start of the line below marked --->.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000262
263 2. Type 2w to move the cursor two words forward.
264
265 3. Type 3e to move the cursor to the end of the third word forward.
266
267 4. Type 0 (zero) to move to the start of the line.
268
269 5. Repeat steps 2 and 3 with different numbers.
270
271---> This is just a line with words you can move around in.
272
RestorerZ6fa304f2024-12-02 20:19:52 +0100273 6. Move on to lesson 1.2.5.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000274
275
276
277
278~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100279 Lesson 1.2.5: USING A COUNT TO DELETE MORE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000280
281
Bram Moolenaar843ee412004-06-30 16:16:41 +0000282 ** Typing a number with an operator repeats it that many times. **
283
284 In the combination of the delete operator and a motion mentioned above you
285 insert a count before the motion to delete more:
286 d number motion
287
288 1. Move the cursor to the first UPPER CASE word in the line marked --->.
289
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200290 2. Type d2w to delete the two UPPER CASE words.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000291
292 3. Repeat steps 1 and 2 with a different count to delete the consecutive
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200293 UPPER CASE words with one command.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000294
295---> this ABC DE line FGHI JK LMN OP of words is Q RS TUV cleaned up.
296
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000297
298
Bram Moolenaar843ee412004-06-30 16:16:41 +0000299
300
301~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100302 Lesson 1.2.6: OPERATING ON LINES
Bram Moolenaar843ee412004-06-30 16:16:41 +0000303
304
305 ** Type dd to delete a whole line. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306
307 Due to the frequency of whole line deletion, the designers of Vi decided
Bram Moolenaar843ee412004-06-30 16:16:41 +0000308 it would be easier to simply type two d's to delete a line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309
310 1. Move the cursor to the second line in the phrase below.
311 2. Type dd to delete the line.
312 3. Now move to the fourth line.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000313 4. Type 2dd to delete two lines.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314
Bram Moolenaar843ee412004-06-30 16:16:41 +0000315---> 1) Roses are red,
316---> 2) Mud is fun,
317---> 3) Violets are blue,
318---> 4) I have a car,
319---> 5) Clocks tell time,
320---> 6) Sugar is sweet
321---> 7) And so are you.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322
Bram Moolenaar4466ad62020-11-21 13:16:30 +0100323Doubling to operate on a line also works for operators mentioned below.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324
325~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100326 Lesson 1.2.7: THE UNDO COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000327
328
Bram Moolenaar843ee412004-06-30 16:16:41 +0000329 ** Press u to undo the last commands, U to fix a whole line. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000330
331 1. Move the cursor to the line below marked ---> and place it on the
332 first error.
333 2. Type x to delete the first unwanted character.
334 3. Now type u to undo the last command executed.
335 4. This time fix all the errors on the line using the x command.
336 5. Now type a capital U to return the line to its original state.
337 6. Now type u a few times to undo the U and preceding commands.
338 7. Now type CTRL-R (keeping CTRL key pressed while hitting R) a few times
Bram Moolenaarbe4e0162023-02-02 13:59:48 +0000339 to redo the commands (undo the undos).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000340
341---> Fiix the errors oon thhis line and reeplace them witth undo.
342
RestorerZ6fa304f2024-12-02 20:19:52 +0100343 8. These are very useful commands. Now move on to the lesson 1.2 Summary.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000344
345
346
347
348~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100349 Lesson 1.2 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350
Bram Moolenaar34cc7d82021-09-21 20:09:51 +0200351 1. To delete from the cursor up to the next word type: dw
352 2. To delete from the cursor up to the end of the word type: de
353 3. To delete from the cursor to the end of a line type: d$
354 4. To delete a whole line type: dd
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355
Bram Moolenaar34cc7d82021-09-21 20:09:51 +0200356 5. To repeat a motion prepend it with a number: 2w
357 6. The format for a change command is:
Bram Moolenaar843ee412004-06-30 16:16:41 +0000358 operator [number] motion
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359 where:
Bram Moolenaar843ee412004-06-30 16:16:41 +0000360 operator - is what to do, such as d for delete
361 [number] - is an optional count to repeat the motion
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000362 motion - moves over the text to operate on, such as w (word),
Bram Moolenaar34cc7d82021-09-21 20:09:51 +0200363 e (end of word), $ (end of the line), etc.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364
Bram Moolenaar34cc7d82021-09-21 20:09:51 +0200365 7. To move to the start of the line use a zero: 0
Bram Moolenaar843ee412004-06-30 16:16:41 +0000366
Bram Moolenaar34cc7d82021-09-21 20:09:51 +0200367 8. To undo previous actions, type: u (lowercase u)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000368 To undo all the changes on a line, type: U (capital U)
Bram Moolenaarbe4e0162023-02-02 13:59:48 +0000369 To undo the undos, type: CTRL-R
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370
371~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100372 Lesson 1.3.1: THE PUT COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373
374
Bram Moolenaar843ee412004-06-30 16:16:41 +0000375 ** Type p to put previously deleted text after the cursor. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376
Bram Moolenaarb477af22018-07-15 20:20:18 +0200377 1. Move the cursor to the first line below marked --->.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378
Bram Moolenaar843ee412004-06-30 16:16:41 +0000379 2. Type dd to delete the line and store it in a Vim register.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380
Bram Moolenaar843ee412004-06-30 16:16:41 +0000381 3. Move the cursor to the c) line, ABOVE where the deleted line should go.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382
Bram Moolenaar843ee412004-06-30 16:16:41 +0000383 4. Type p to put the line below the cursor.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000384
385 5. Repeat steps 2 through 4 to put all the lines in correct order.
386
Bram Moolenaar843ee412004-06-30 16:16:41 +0000387---> d) Can you learn too?
388---> b) Violets are blue,
389---> c) Intelligence is learned,
390---> a) Roses are red,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000391
392
393
394~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100395 Lesson 1.3.2: THE REPLACE COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396
397
Bram Moolenaar843ee412004-06-30 16:16:41 +0000398 ** Type rx to replace the character at the cursor with x . **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399
400 1. Move the cursor to the first line below marked --->.
401
402 2. Move the cursor so that it is on top of the first error.
403
Bram Moolenaar843ee412004-06-30 16:16:41 +0000404 3. Type r and then the character which should be there.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000405
Bram Moolenaar843ee412004-06-30 16:16:41 +0000406 4. Repeat steps 2 and 3 until the first line is equal to the second one.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000407
408---> Whan this lime was tuoed in, someone presswd some wrojg keys!
409---> When this line was typed in, someone pressed some wrong keys!
410
RestorerZ6fa304f2024-12-02 20:19:52 +0100411 5. Now move on to lesson 1.3.3.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000412
Bram Moolenaar843ee412004-06-30 16:16:41 +0000413NOTE: Remember that you should be learning by doing, not memorization.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414
415
416
417~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100418 Lesson 1.3.3: THE CHANGE OPERATOR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000419
420
Bram Moolenaar843ee412004-06-30 16:16:41 +0000421 ** To change until the end of a word, type ce . **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000422
423 1. Move the cursor to the first line below marked --->.
424
Bram Moolenaar843ee412004-06-30 16:16:41 +0000425 2. Place the cursor on the u in lubw.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426
Bram Moolenaar843ee412004-06-30 16:16:41 +0000427 3. Type ce and the correct word (in this case, type ine ).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000428
Bram Moolenaar843ee412004-06-30 16:16:41 +0000429 4. Press <ESC> and move to the next character that needs to be changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430
431 5. Repeat steps 3 and 4 until the first sentence is the same as the second.
432
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000433---> This lubw has a few wptfd that mrrf changing usf the change operator.
434---> This line has a few words that need changing using the change operator.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000435
Bram Moolenaar843ee412004-06-30 16:16:41 +0000436Notice that ce deletes the word and places you in Insert mode.
Bram Moolenaar4466ad62020-11-21 13:16:30 +0100437 cc does the same for the whole line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000438
439
440~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100441 Lesson 1.3.4: MORE CHANGES USING c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000442
443
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000444 ** The change operator is used with the same motions as delete. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000445
Bram Moolenaar843ee412004-06-30 16:16:41 +0000446 1. The change operator works in the same way as delete. The format is:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000447
Bram Moolenaar843ee412004-06-30 16:16:41 +0000448 c [number] motion
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449
Bram Moolenaar843ee412004-06-30 16:16:41 +0000450 2. The motions are the same, such as w (word) and $ (end of line).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451
Bram Moolenaarb477af22018-07-15 20:20:18 +0200452 3. Move the cursor to the first line below marked --->.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000453
454 4. Move the cursor to the first error.
455
Bram Moolenaar843ee412004-06-30 16:16:41 +0000456 5. Type c$ and type the rest of the line like the second and press <ESC>.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000457
458---> The end of this line needs some help to make it like the second.
459---> The end of this line needs to be corrected using the c$ command.
460
Bram Moolenaar843ee412004-06-30 16:16:41 +0000461NOTE: You can use the Backspace key to correct mistakes while typing.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000462
463~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100464 Lesson 1.3 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
466
Bram Moolenaar843ee412004-06-30 16:16:41 +0000467 1. To put back text that has just been deleted, type p . This puts the
Bram Moolenaar071d4272004-06-13 20:20:40 +0000468 deleted text AFTER the cursor (if a line was deleted it will go on the
469 line below the cursor).
470
471 2. To replace the character under the cursor, type r and then the
Bram Moolenaar843ee412004-06-30 16:16:41 +0000472 character you want to have there.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000473
Bram Moolenaar843ee412004-06-30 16:16:41 +0000474 3. The change operator allows you to change from the cursor to where the
475 motion takes you. eg. Type ce to change from the cursor to the end of
476 the word, c$ to change to the end of a line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000477
478 4. The format for change is:
479
Bram Moolenaar843ee412004-06-30 16:16:41 +0000480 c [number] motion
Bram Moolenaar071d4272004-06-13 20:20:40 +0000481
482Now go on to the next lesson.
483
484
485
486~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100487 Lesson 1.4.1: CURSOR LOCATION AND FILE STATUS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000488
Bram Moolenaar843ee412004-06-30 16:16:41 +0000489 ** Type CTRL-G to show your location in the file and the file status.
490 Type G to move to a line in the file. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000491
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000492 NOTE: Read this entire lesson before executing any of the steps!!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000493
Bram Moolenaar843ee412004-06-30 16:16:41 +0000494 1. Hold down the Ctrl key and press g . We call this CTRL-G.
495 A message will appear at the bottom of the page with the filename and the
496 position in the file. Remember the line number for Step 3.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497
Bram Moolenaar843ee412004-06-30 16:16:41 +0000498NOTE: You may see the cursor position in the lower right corner of the screen
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000499 This happens when the 'ruler' option is set (see :help 'ruler' )
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500
Bram Moolenaar843ee412004-06-30 16:16:41 +0000501 2. Press G to move you to the bottom of the file.
502 Type gg to move you to the start of the file.
503
504 3. Type the number of the line you were on and then G . This will
505 return you to the line you were on when you first pressed CTRL-G.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506
507 4. If you feel confident to do this, execute steps 1 through 3.
508
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100510 Lesson 1.4.2: THE SEARCH COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511
512
513 ** Type / followed by a phrase to search for the phrase. **
514
515 1. In Normal mode type the / character. Notice that it and the cursor
516 appear at the bottom of the screen as with the : command.
517
518 2. Now type 'errroor' <ENTER>. This is the word you want to search for.
519
520 3. To search for the same phrase again, simply type n .
Bram Moolenaar843ee412004-06-30 16:16:41 +0000521 To search for the same phrase in the opposite direction, type N .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522
Bram Moolenaar843ee412004-06-30 16:16:41 +0000523 4. To search for a phrase in the backward direction, use ? instead of / .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524
Bram Moolenaar843ee412004-06-30 16:16:41 +0000525 5. To go back to where you came from press CTRL-O (Keep Ctrl down while
526 pressing the letter o). Repeat to go back further. CTRL-I goes forward.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000527
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000528---> "errroor" is not the way to spell error; errroor is an error.
529NOTE: When the search reaches the end of the file it will continue at the
Bram Moolenaar843ee412004-06-30 16:16:41 +0000530 start, unless the 'wrapscan' option has been reset.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000531
532~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100533 Lesson 1.4.3: MATCHING PARENTHESES SEARCH
Bram Moolenaar071d4272004-06-13 20:20:40 +0000534
535
536 ** Type % to find a matching ),], or } . **
537
538 1. Place the cursor on any (, [, or { in the line below marked --->.
539
540 2. Now type the % character.
541
Bram Moolenaar843ee412004-06-30 16:16:41 +0000542 3. The cursor will move to the matching parenthesis or bracket.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000543
Bram Moolenaar843ee412004-06-30 16:16:41 +0000544 4. Type % to move the cursor to the other matching bracket.
545
546 5. Move the cursor to another (,),[,],{ or } and see what % does.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547
548---> This ( is a test line with ('s, ['s ] and {'s } in it. ))
549
Bram Moolenaar843ee412004-06-30 16:16:41 +0000550
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000551NOTE: This is very useful in debugging a program with unmatched parentheses!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552
553
554
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100556 Lesson 1.4.4: THE SUBSTITUTE COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557
558
559 ** Type :s/old/new/g to substitute 'new' for 'old'. **
560
561 1. Move the cursor to the line below marked --->.
562
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200563 2. Type :s/thee/the <ENTER> . Note that this command only changes the
Bram Moolenaar843ee412004-06-30 16:16:41 +0000564 first occurrence of "thee" in the line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565
Bram Moolenaar843ee412004-06-30 16:16:41 +0000566 3. Now type :s/thee/the/g . Adding the g flag means to substitute
567 globally in the line, change all occurrences of "thee" in the line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568
569---> thee best time to see thee flowers is in thee spring.
570
571 4. To change every occurrence of a character string between two lines,
Bram Moolenaar843ee412004-06-30 16:16:41 +0000572 type :#,#s/old/new/g where #,# are the line numbers of the range
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000573 of lines where the substitution is to be done.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000574 Type :%s/old/new/g to change every occurrence in the whole file.
575 Type :%s/old/new/gc to find every occurrence in the whole file,
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000576 with a prompt whether to substitute or not.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577
578~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100579 Lesson 1.4 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580
581
Bram Moolenaar843ee412004-06-30 16:16:41 +0000582 1. CTRL-G displays your location in the file and the file status.
583 G moves to the end of the file.
584 number G moves to that line number.
585 gg moves to the first line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586
587 2. Typing / followed by a phrase searches FORWARD for the phrase.
588 Typing ? followed by a phrase searches BACKWARD for the phrase.
589 After a search type n to find the next occurrence in the same direction
Bram Moolenaar843ee412004-06-30 16:16:41 +0000590 or N to search in the opposite direction.
591 CTRL-O takes you back to older positions, CTRL-I to newer positions.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592
Bram Moolenaar843ee412004-06-30 16:16:41 +0000593 3. Typing % while the cursor is on a (,),[,],{, or } goes to its match.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594
Bram Moolenaar843ee412004-06-30 16:16:41 +0000595 4. To substitute new for the first old in a line type :s/old/new
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 To substitute new for all 'old's on a line type :s/old/new/g
597 To substitute phrases between two line #'s type :#,#s/old/new/g
598 To substitute all occurrences in the file type :%s/old/new/g
599 To ask for confirmation each time add 'c' :%s/old/new/gc
600
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100602 Lesson 1.5.1: HOW TO EXECUTE AN EXTERNAL COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603
604
605 ** Type :! followed by an external command to execute that command. **
606
607 1. Type the familiar command : to set the cursor at the bottom of the
Bram Moolenaar843ee412004-06-30 16:16:41 +0000608 screen. This allows you to enter a command-line command.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609
610 2. Now type the ! (exclamation point) character. This allows you to
611 execute any external shell command.
612
613 3. As an example type ls following the ! and then hit <ENTER>. This
614 will show you a listing of your directory, just as if you were at the
Bram Moolenaar843ee412004-06-30 16:16:41 +0000615 shell prompt. Or use :!dir if ls doesn't work.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000616
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000617NOTE: It is possible to execute any external command this way, also with
Bram Moolenaar843ee412004-06-30 16:16:41 +0000618 arguments.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000620NOTE: All : commands must be finished by hitting <ENTER>
621 From here on we will not always mention it.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622
623
624~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100625 Lesson 1.5.2: MORE ON WRITING FILES
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626
627
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200628 ** To save the changes made to the text, type :w FILENAME **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629
630 1. Type :!dir or :!ls to get a listing of your directory.
631 You already know you must hit <ENTER> after this.
632
633 2. Choose a filename that does not exist yet, such as TEST.
634
635 3. Now type: :w TEST (where TEST is the filename you chose.)
636
Bram Moolenaar843ee412004-06-30 16:16:41 +0000637 4. This saves the whole file (the Vim Tutor) under the name TEST.
638 To verify this, type :!dir or :!ls again to see your directory.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000640NOTE: If you were to exit Vim and start it again with vim TEST , the file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000641 would be an exact copy of the tutor when you saved it.
642
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200643 5. Now remove the file by typing (Windows): :!del TEST
Bram Moolenaar071d4272004-06-13 20:20:40 +0000644 or (Unix): :!rm TEST
645
646
647~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100648 Lesson 1.5.3: SELECTING TEXT TO WRITE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649
650
Bram Moolenaar843ee412004-06-30 16:16:41 +0000651 ** To save part of the file, type v motion :w FILENAME **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000652
Bram Moolenaar843ee412004-06-30 16:16:41 +0000653 1. Move the cursor to this line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654
Bram Moolenaar843ee412004-06-30 16:16:41 +0000655 2. Press v and move the cursor to the fifth item below. Notice that the
656 text is highlighted.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000657
Bram Moolenaar843ee412004-06-30 16:16:41 +0000658 3. Press the : character. At the bottom of the screen :'<,'> will appear.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000659
Bram Moolenaar843ee412004-06-30 16:16:41 +0000660 4. Type w TEST , where TEST is a filename that does not exist yet. Verify
Bram Moolenaar59c03952010-07-28 12:52:27 +0200661 that you see :'<,'>w TEST before you press <ENTER>.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000662
Bram Moolenaar97cc2382012-10-03 21:46:54 +0200663 5. Vim will write the selected lines to the file TEST. Use :!dir or :!ls
Bram Moolenaar843ee412004-06-30 16:16:41 +0000664 to see it. Do not remove it yet! We will use it in the next lesson.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665
Bram Moolenaar843ee412004-06-30 16:16:41 +0000666NOTE: Pressing v starts Visual selection. You can move the cursor around
667 to make the selection bigger or smaller. Then you can use an operator
668 to do something with the text. For example, d deletes the text.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669
670~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100671 Lesson 1.5.4: RETRIEVING AND MERGING FILES
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672
673
Bram Moolenaar843ee412004-06-30 16:16:41 +0000674 ** To insert the contents of a file, type :r FILENAME **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675
Bram Moolenaar843ee412004-06-30 16:16:41 +0000676 1. Place the cursor just above this line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677
RestorerZ6fa304f2024-12-02 20:19:52 +0100678NOTE: After executing Step 2 you will see text from lesson 1.5.3. Then move
Bram Moolenaar843ee412004-06-30 16:16:41 +0000679 DOWN to see this lesson again.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680
Bram Moolenaar843ee412004-06-30 16:16:41 +0000681 2. Now retrieve your TEST file using the command :r TEST where TEST is
682 the name of the file you used.
683 The file you retrieve is placed below the cursor line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684
Bram Moolenaar843ee412004-06-30 16:16:41 +0000685 3. To verify that a file was retrieved, cursor back and notice that there
RestorerZ6fa304f2024-12-02 20:19:52 +0100686 are now two copies of lesson 1.5.3, the original and the file version.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000687
Bram Moolenaar843ee412004-06-30 16:16:41 +0000688NOTE: You can also read the output of an external command. For example,
689 :r !ls reads the output of the ls command and puts it below the
690 cursor.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000691
692
693~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100694 Lesson 1.5 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695
696
697 1. :!command executes an external command.
698
699 Some useful examples are:
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200700 (Windows) (Unix)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000701 :!dir :!ls - shows a directory listing.
702 :!del FILENAME :!rm FILENAME - removes file FILENAME.
703
704 2. :w FILENAME writes the current Vim file to disk with name FILENAME.
705
Bram Moolenaar843ee412004-06-30 16:16:41 +0000706 3. v motion :w FILENAME saves the Visually selected lines in file
707 FILENAME.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708
Bram Moolenaar843ee412004-06-30 16:16:41 +0000709 4. :r FILENAME retrieves disk file FILENAME and puts it below the
710 cursor position.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711
Bram Moolenaar843ee412004-06-30 16:16:41 +0000712 5. :r !dir reads the output of the dir command and puts it below the
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000713 cursor position.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714
715
716~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100717 Lesson 1.6.1: THE OPEN COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718
719
720 ** Type o to open a line below the cursor and place you in Insert mode. **
721
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200722 1. Move the cursor to the first line below marked --->.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723
Bram Moolenaar843ee412004-06-30 16:16:41 +0000724 2. Type the lowercase letter o to open up a line BELOW the cursor and place
725 you in Insert mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726
Bram Moolenaar843ee412004-06-30 16:16:41 +0000727 3. Now type some text and press <ESC> to exit Insert mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728
729---> After typing o the cursor is placed on the open line in Insert mode.
730
731 4. To open up a line ABOVE the cursor, simply type a capital O , rather
732 than a lowercase o. Try this on the line below.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733
Bram Moolenaar843ee412004-06-30 16:16:41 +0000734---> Open up a line above this by typing O while the cursor is on this line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000735
736
737
738
739~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100740 Lesson 1.6.2: THE APPEND COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741
742
743 ** Type a to insert text AFTER the cursor. **
744
Bram Moolenaarb477af22018-07-15 20:20:18 +0200745 1. Move the cursor to the start of the first line below marked --->.
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200746
Bram Moolenaar843ee412004-06-30 16:16:41 +0000747 2. Press e until the cursor is on the end of li .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748
Bram Moolenaar843ee412004-06-30 16:16:41 +0000749 3. Type an a (lowercase) to append text AFTER the cursor.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750
Bram Moolenaar843ee412004-06-30 16:16:41 +0000751 4. Complete the word like the line below it. Press <ESC> to exit Insert
752 mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000753
Bram Moolenaar843ee412004-06-30 16:16:41 +0000754 5. Use e to move to the next incomplete word and repeat steps 3 and 4.
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200755
Bram Moolenaar843ee412004-06-30 16:16:41 +0000756---> This li will allow you to pract appendi text to a line.
757---> This line will allow you to practice appending text to a line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000759NOTE: a, i and A all go to the same Insert mode, the only difference is where
Bram Moolenaar843ee412004-06-30 16:16:41 +0000760 the characters are inserted.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761
762~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100763 Lesson 1.6.3: ANOTHER WAY TO REPLACE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764
765
766 ** Type a capital R to replace more than one character. **
767
Bram Moolenaar843ee412004-06-30 16:16:41 +0000768 1. Move the cursor to the first line below marked --->. Move the cursor to
769 the beginning of the first xxx .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000770
Bram Moolenaar843ee412004-06-30 16:16:41 +0000771 2. Now press R and type the number below it in the second line, so that it
772 replaces the xxx .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000773
Bram Moolenaar843ee412004-06-30 16:16:41 +0000774 3. Press <ESC> to leave Replace mode. Notice that the rest of the line
775 remains unmodified.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000777 4. Repeat the steps to replace the remaining xxx.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000778
Bram Moolenaar843ee412004-06-30 16:16:41 +0000779---> Adding 123 to xxx gives you xxx.
780---> Adding 123 to 456 gives you 579.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000781
Bram Moolenaar843ee412004-06-30 16:16:41 +0000782NOTE: Replace mode is like Insert mode, but every typed character deletes an
783 existing character.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784
785~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100786 Lesson 1.6.4: COPY AND PASTE TEXT
Bram Moolenaar843ee412004-06-30 16:16:41 +0000787
788
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000789 ** Use the y operator to copy text and p to paste it **
Bram Moolenaar843ee412004-06-30 16:16:41 +0000790
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200791 1. Move to the line below marked ---> and place the cursor after "a)".
792
Bram Moolenaar843ee412004-06-30 16:16:41 +0000793 2. Start Visual mode with v and move the cursor to just before "first".
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200794
Bram Moolenaar843ee412004-06-30 16:16:41 +0000795 3. Type y to yank (copy) the highlighted text.
796
797 4. Move the cursor to the end of the next line: j$
798
799 5. Type p to put (paste) the text. Then type: a second <ESC> .
800
801 6. Use Visual mode to select " item.", yank it with y , move to the end of
802 the next line with j$ and put the text there with p .
803
804---> a) this is the first item.
805 b)
806
Bram Moolenaar1c6737b2020-09-07 22:18:52 +0200807 NOTE: You can also use y as an operator: yw yanks one word,
Bram Moolenaar4466ad62020-11-21 13:16:30 +0100808 yy yanks the whole line, then p puts that line.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000809~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100810 Lesson 1.6.5: SET OPTION
Bram Moolenaar843ee412004-06-30 16:16:41 +0000811
Bram Moolenaar071d4272004-06-13 20:20:40 +0000812
813 ** Set an option so a search or substitute ignores case **
814
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200815 1. Search for 'ignore' by entering: /ignore <ENTER>
Bram Moolenaar843ee412004-06-30 16:16:41 +0000816 Repeat several times by pressing n .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000817
Bram Moolenaar843ee412004-06-30 16:16:41 +0000818 2. Set the 'ic' (Ignore case) option by entering: :set ic
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819
Bram Moolenaar843ee412004-06-30 16:16:41 +0000820 3. Now search for 'ignore' again by pressing n
821 Notice that Ignore and IGNORE are now also found.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822
Bram Moolenaar843ee412004-06-30 16:16:41 +0000823 4. Set the 'hlsearch' and 'incsearch' options: :set hls is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000824
Bram Moolenaar843ee412004-06-30 16:16:41 +0000825 5. Now type the search command again and see what happens: /ignore <ENTER>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000826
Bram Moolenaar843ee412004-06-30 16:16:41 +0000827 6. To disable ignoring case enter: :set noic
828
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200829NOTE: To remove the highlighting of matches enter: :nohlsearch
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000830NOTE: If you want to ignore case for just one search command, use \c
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200831 in the phrase: /ignore\c <ENTER>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000832~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100833 Lesson 1.6 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000834
Bram Moolenaar843ee412004-06-30 16:16:41 +0000835 1. Type o to open a line BELOW the cursor and start Insert mode.
836 Type O to open a line ABOVE the cursor.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837
Bram Moolenaar843ee412004-06-30 16:16:41 +0000838 2. Type a to insert text AFTER the cursor.
839 Type A to insert text after the end of the line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000840
Bram Moolenaar843ee412004-06-30 16:16:41 +0000841 3. The e command moves to the end of a word.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000842
Bram Moolenaar843ee412004-06-30 16:16:41 +0000843 4. The y operator yanks (copies) text, p puts (pastes) it.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000844
Bram Moolenaar843ee412004-06-30 16:16:41 +0000845 5. Typing a capital R enters Replace mode until <ESC> is pressed.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846
Bram Moolenaar843ee412004-06-30 16:16:41 +0000847 6. Typing ":set xxx" sets the option "xxx". Some options are:
848 'ic' 'ignorecase' ignore upper/lower case when searching
849 'is' 'incsearch' show partial matches for a search phrase
850 'hls' 'hlsearch' highlight all matching phrases
851 You can either use the long or the short option name.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000852
Bram Moolenaar843ee412004-06-30 16:16:41 +0000853 7. Prepend "no" to switch an option off: :set noic
Bram Moolenaar071d4272004-06-13 20:20:40 +0000854
855~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100856 Lesson 1.7.1: GETTING HELP
Bram Moolenaar071d4272004-06-13 20:20:40 +0000857
858
859 ** Use the on-line help system **
860
861 Vim has a comprehensive on-line help system. To get started, try one of
862 these three:
863 - press the <HELP> key (if you have one)
864 - press the <F1> key (if you have one)
865 - type :help <ENTER>
866
Bram Moolenaar843ee412004-06-30 16:16:41 +0000867 Read the text in the help window to find out how the help works.
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000868 Type CTRL-W CTRL-W to jump from one window to another.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000869 Type :q <ENTER> to close the help window.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000870
871 You can find help on just about any subject, by giving an argument to the
872 ":help" command. Try these (don't forget pressing <ENTER>):
873
874 :help w
Bram Moolenaar843ee412004-06-30 16:16:41 +0000875 :help c_CTRL-D
Bram Moolenaar071d4272004-06-13 20:20:40 +0000876 :help insert-index
877 :help user-manual
Bram Moolenaar071d4272004-06-13 20:20:40 +0000878~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100879 Lesson 1.7.2: CREATE A STARTUP SCRIPT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000880
Bram Moolenaar071d4272004-06-13 20:20:40 +0000881
Bram Moolenaar843ee412004-06-30 16:16:41 +0000882 ** Enable Vim features **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883
Bram Moolenaar843ee412004-06-30 16:16:41 +0000884 Vim has many more features than Vi, but most of them are disabled by
Bram Moolenaard2ea7cf2021-05-30 20:54:13 +0200885 default. To start using more features you should create a "vimrc" file.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886
Bram Moolenaar843ee412004-06-30 16:16:41 +0000887 1. Start editing the "vimrc" file. This depends on your system:
888 :e ~/.vimrc for Unix
Bram Moolenaard2ea7cf2021-05-30 20:54:13 +0200889 :e ~/_vimrc for Windows
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890
Bram Moolenaar843ee412004-06-30 16:16:41 +0000891 2. Now read the example "vimrc" file contents:
892 :r $VIMRUNTIME/vimrc_example.vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893
894 3. Write the file with:
Bram Moolenaar843ee412004-06-30 16:16:41 +0000895 :w
Bram Moolenaar071d4272004-06-13 20:20:40 +0000896
897 The next time you start Vim it will use syntax highlighting.
898 You can add all your preferred settings to this "vimrc" file.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000899 For more information type :help vimrc-intro
900
901~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100902 Lesson 1.7.3: COMPLETION
Bram Moolenaar843ee412004-06-30 16:16:41 +0000903
904
905 ** Command line completion with CTRL-D and <TAB> **
906
907 1. Make sure Vim is not in compatible mode: :set nocp
908
909 2. Look what files exist in the directory: :!ls or :!dir
910
911 3. Type the start of a command: :e
912
913 4. Press CTRL-D and Vim will show a list of commands that start with "e".
914
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200915 5. Type d<TAB> and Vim will complete the command name to ":edit".
Bram Moolenaar843ee412004-06-30 16:16:41 +0000916
917 6. Now add a space and the start of an existing file name: :edit FIL
918
919 7. Press <TAB>. Vim will complete the name (if it is unique).
920
921NOTE: Completion works for many commands. Just try pressing CTRL-D and
922 <TAB>. It is especially useful for :help .
923
924~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100925 Lesson 1.7 SUMMARY
Bram Moolenaar843ee412004-06-30 16:16:41 +0000926
927
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200928 1. Type :help or press <F1> or <HELP> to open a help window.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000929
930 2. Type :help cmd to find help on cmd .
931
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200932 3. Type CTRL-W CTRL-W to jump to another window.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000933
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200934 4. Type :q to close the help window.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000935
936 5. Create a vimrc startup script to keep your preferred settings.
937
938 6. When typing a : command, press CTRL-D to see possible completions.
939 Press <TAB> to use one completion.
940
941
942
943
944
945
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946
947~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
948
Paul Desmond Parker17c71da2024-11-03 20:47:53 +0100949 This concludes Chapter 1 of the Vim Tutor. Consider continuing with Chapter 2.
950
951 It was intended to give a brief overview of the Vim editor, just enough to
952 allow you to use the editor fairly easily. It is far from complete as Vim
953 has many many more commands.
954
955 Read the user manual next: ":help user-manual".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000956
957 For further reading and studying, this book is recommended:
958 Vim - Vi Improved - by Steve Oualline
959 Publisher: New Riders
960 The first book completely dedicated to Vim. Especially useful for beginners.
961 There are many examples and pictures.
Bram Moolenaar9da17d72022-02-09 21:50:44 +0000962 See https://iccf-holland.org/click5.html
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963
964 This book is older and more about Vi than Vim, but also recommended:
965 Learning the Vi Editor - by Linda Lamb
966 Publisher: O'Reilly & Associates Inc.
967 It is a good book to get to know almost anything you want to do with Vi.
968 The sixth edition also includes information on Vim.
969
970 This tutorial was written by Michael C. Pierce and Robert K. Ware,
971 Colorado School of Mines using ideas supplied by Charles Smith,
972 Colorado State University. E-mail: bware@mines.colorado.edu.
973
974 Modified for Vim by Bram Moolenaar.
975
976~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~