blob: 04b490f0c9066b2f980a34f0998480f069750b8e [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
Ken Takatab183f502024-12-19 20:03:10 +010022 the j key enough times to move the cursor so that lesson 1.1.1
Bram Moolenaar071d4272004-06-13 20:20:40 +000023 completely fills the screen.
24~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +010025 Lesson 1.1.1: MOVING THE CURSOR
Bram Moolenaar071d4272004-06-13 20:20:40 +000026
27
28 ** To move the cursor, press the h,j,k,l keys as indicated. **
29 ^
30 k Hint: The h key is at the left and moves left.
31 < h l > The l key is at the right and moves right.
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000032 j The j key looks like a down arrow.
Bram Moolenaar071d4272004-06-13 20:20:40 +000033 v
34 1. Move the cursor around the screen until you are comfortable.
35
36 2. Hold down the down key (j) until it repeats.
Bram Moolenaar843ee412004-06-30 16:16:41 +000037 Now you know how to move to the next lesson.
Bram Moolenaar071d4272004-06-13 20:20:40 +000038
RestorerZ6fa304f2024-12-02 20:19:52 +010039 3. Using the down key, move to lesson 1.1.2.
Bram Moolenaar071d4272004-06-13 20:20:40 +000040
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000041NOTE: If you are ever unsure about something you typed, press <ESC> to place
Bram Moolenaar071d4272004-06-13 20:20:40 +000042 you in Normal mode. Then retype the command you wanted.
43
Bram Moolenaar756ec0f2007-05-05 17:59:48 +000044NOTE: The cursor keys should also work. But using hjkl you will be able to
Bram Moolenaar843ee412004-06-30 16:16:41 +000045 move around much faster, once you get used to it. Really!
Bram Moolenaar071d4272004-06-13 20:20:40 +000046
47~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +010048 Lesson 1.1.2: EXITING VIM
Bram Moolenaar071d4272004-06-13 20:20:40 +000049
50
51 !! NOTE: Before executing any of the steps below, read this entire lesson!!
52
53 1. Press the <ESC> key (to make sure you are in Normal mode).
54
Bram Moolenaar843ee412004-06-30 16:16:41 +000055 2. Type: :q! <ENTER>.
56 This exits the editor, DISCARDING any changes you have made.
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
Bram Moolenaardfb18412013-12-11 18:53:29 +010058 3. Get back here by executing the command that got you into this tutor. That
59 might be: vimtutor <ENTER>
Bram Moolenaar071d4272004-06-13 20:20:40 +000060
61 4. If you have these steps memorized and are confident, execute steps
Bram Moolenaar843ee412004-06-30 16:16:41 +000062 1 through 3 to exit and re-enter the editor.
63
64NOTE: :q! <ENTER> discards any changes you made. In a few lessons you
65 will learn how to save the changes to a file.
66
RestorerZ6fa304f2024-12-02 20:19:52 +010067 5. Move the cursor down to lesson 1.1.3.
Bram Moolenaar843ee412004-06-30 16:16:41 +000068
69
Bram Moolenaar071d4272004-06-13 20:20:40 +000070~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +010071 Lesson 1.1.3: TEXT EDITING - DELETION
Bram Moolenaar071d4272004-06-13 20:20:40 +000072
73
Bram Moolenaar843ee412004-06-30 16:16:41 +000074 ** Press x to delete the character under the cursor. **
Bram Moolenaar071d4272004-06-13 20:20:40 +000075
76 1. Move the cursor to the line below marked --->.
77
78 2. To fix the errors, move the cursor until it is on top of the
79 character to be deleted.
80
81 3. Press the x key to delete the unwanted character.
82
83 4. Repeat steps 2 through 4 until the sentence is correct.
84
85---> The ccow jumpedd ovverr thhe mooon.
86
RestorerZ6fa304f2024-12-02 20:19:52 +010087 5. Now that the line is correct, go on to lesson 1.1.4.
Bram Moolenaar071d4272004-06-13 20:20:40 +000088
89NOTE: As you go through this tutor, do not try to memorize, learn by usage.
90
91
92
93~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +010094 Lesson 1.1.4: TEXT EDITING - INSERTION
Bram Moolenaar071d4272004-06-13 20:20:40 +000095
96
Bram Moolenaar843ee412004-06-30 16:16:41 +000097 ** Press i to insert text. **
Bram Moolenaar071d4272004-06-13 20:20:40 +000098
99 1. Move the cursor to the first line below marked --->.
100
101 2. To make the first line the same as the second, move the cursor on top
Bram Moolenaar4c92e752019-02-17 21:18:32 +0100102 of the character BEFORE which the text is to be inserted.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103
104 3. Press i and type in the necessary additions.
105
106 4. As each error is fixed press <ESC> to return to Normal mode.
107 Repeat steps 2 through 4 to correct the sentence.
108
109---> There is text misng this .
110---> There is some text missing from this line.
111
RestorerZ6fa304f2024-12-02 20:19:52 +0100112 5. When you are comfortable inserting text move to lesson 1.1.5.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113
114
115
116~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100117 Lesson 1.1.5: TEXT EDITING - APPENDING
Bram Moolenaar843ee412004-06-30 16:16:41 +0000118
119
120 ** Press A to append text. **
121
122 1. Move the cursor to the first line below marked --->.
123 It does not matter on what character the cursor is in that line.
124
125 2. Press A and type in the necessary additions.
126
127 3. As the text has been appended press <ESC> to return to Normal mode.
128
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200129 4. Move the cursor to the second line marked ---> and repeat
Bram Moolenaar843ee412004-06-30 16:16:41 +0000130 steps 2 and 3 to correct this sentence.
131
132---> There is some text missing from th
133 There is some text missing from this line.
134---> There is also some text miss
135 There is also some text missing here.
136
RestorerZ6fa304f2024-12-02 20:19:52 +0100137 5. When you are comfortable appending text move to lesson 1.1.6.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000138
139~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100140 Lesson 1.1.6: EDITING A FILE
Bram Moolenaar843ee412004-06-30 16:16:41 +0000141
Bram Moolenaar843ee412004-06-30 16:16:41 +0000142 ** Use :wq to save a file and exit. **
143
144 !! NOTE: Before executing any of the steps below, read this entire lesson!!
145
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200146 1. If you have access to another terminal, do the following there.
RestorerZ6fa304f2024-12-02 20:19:52 +0100147 Otherwise, exit this tutor as you did in lesson 1.1.2: :q!
Bram Moolenaar843ee412004-06-30 16:16:41 +0000148
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200149 2. At the shell prompt type this command: vim file.txt <ENTER>
150 'vim' is the command to start the Vim editor, 'file.txt' is the name of
151 the file you wish to edit. Use the name of a file that you can change.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000152
153 3. Insert and delete text as you learned in the previous lessons.
154
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200155 4. Save the file with changes and exit Vim with: :wq <ENTER>
Bram Moolenaar843ee412004-06-30 16:16:41 +0000156
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +0000157 5. If you have quit vimtutor in step 1 restart the vimtutor and move down to
158 the following summary.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000159
160 6. After reading the above steps and understanding them: do it.
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200161
Bram Moolenaar843ee412004-06-30 16:16:41 +0000162~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100163 Lesson 1.1 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000164
165
166 1. The cursor is moved using either the arrow keys or the hjkl keys.
167 h (left) j (down) k (up) l (right)
168
Bram Moolenaar843ee412004-06-30 16:16:41 +0000169 2. To start Vim from the shell prompt type: vim FILENAME <ENTER>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170
171 3. To exit Vim type: <ESC> :q! <ENTER> to trash all changes.
172 OR type: <ESC> :wq <ENTER> to save the changes.
173
Bram Moolenaar843ee412004-06-30 16:16:41 +0000174 4. To delete the character at the cursor type: x
Bram Moolenaar071d4272004-06-13 20:20:40 +0000175
Bram Moolenaar843ee412004-06-30 16:16:41 +0000176 5. To insert or append text type:
177 i type inserted text <ESC> insert before the cursor
178 A type appended text <ESC> append after the line
Bram Moolenaar071d4272004-06-13 20:20:40 +0000179
180NOTE: Pressing <ESC> will place you in Normal mode or will cancel
181 an unwanted and partially completed command.
182
RestorerZ6fa304f2024-12-02 20:19:52 +0100183Now continue with lesson 1.2.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184
Bram Moolenaar071d4272004-06-13 20:20:40 +0000185~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100186 Lesson 1.2.1: DELETION COMMANDS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000187
188
Bram Moolenaar843ee412004-06-30 16:16:41 +0000189 ** Type dw to delete a word. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190
191 1. Press <ESC> to make sure you are in Normal mode.
192
193 2. Move the cursor to the line below marked --->.
194
195 3. Move the cursor to the beginning of a word that needs to be deleted.
196
197 4. Type dw to make the word disappear.
198
Bram Moolenaar843ee412004-06-30 16:16:41 +0000199 NOTE: The letter d will appear on the last line of the screen as you type
200 it. Vim is waiting for you to type w . If you see another character
201 than d you typed something wrong; press <ESC> and start over.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000202
203---> There are a some words fun that don't belong paper in this sentence.
204
RestorerZ6fa304f2024-12-02 20:19:52 +0100205 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 +0000206
207
Bram Moolenaar071d4272004-06-13 20:20:40 +0000208~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100209 Lesson 1.2.2: MORE DELETION COMMANDS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000210
211
212 ** Type d$ to delete to the end of the line. **
213
214 1. Press <ESC> to make sure you are in Normal mode.
215
216 2. Move the cursor to the line below marked --->.
217
218 3. Move the cursor to the end of the correct line (AFTER the first . ).
219
220 4. Type d$ to delete to the end of the line.
221
222---> Somebody typed the end of this line twice. end of this line twice.
223
224
RestorerZ6fa304f2024-12-02 20:19:52 +0100225 5. Move on to lesson 1.2.3 to understand what is happening.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000226
227
228
229
230
231~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100232 Lesson 1.2.3: ON OPERATORS AND MOTIONS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000233
234
Bram Moolenaar843ee412004-06-30 16:16:41 +0000235 Many commands that change text are made from an operator and a motion.
236 The format for a delete command with the d delete operator is as follows:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000237
Bram Moolenaar843ee412004-06-30 16:16:41 +0000238 d motion
239
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240 Where:
Bram Moolenaar843ee412004-06-30 16:16:41 +0000241 d - is the delete operator.
242 motion - is what the operator will operate on (listed below).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000243
Bram Moolenaar843ee412004-06-30 16:16:41 +0000244 A short list of motions:
245 w - until the start of the next word, EXCLUDING its first character.
246 e - to the end of the current word, INCLUDING the last character.
247 $ - to the end of the line, INCLUDING the last character.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248
Bram Moolenaar843ee412004-06-30 16:16:41 +0000249 Thus typing de will delete from the cursor to the end of the word.
250
251NOTE: Pressing just the motion while in Normal mode without an operator will
252 move the cursor as specified.
253
254~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100255 Lesson 1.2.4: USING A COUNT FOR A MOTION
Bram Moolenaar843ee412004-06-30 16:16:41 +0000256
257
258 ** Typing a number before a motion repeats it that many times. **
259
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200260 1. Move the cursor to the start of the line below marked --->.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000261
262 2. Type 2w to move the cursor two words forward.
263
264 3. Type 3e to move the cursor to the end of the third word forward.
265
266 4. Type 0 (zero) to move to the start of the line.
267
268 5. Repeat steps 2 and 3 with different numbers.
269
270---> This is just a line with words you can move around in.
271
RestorerZ6fa304f2024-12-02 20:19:52 +0100272 6. Move on to lesson 1.2.5.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273
274
275
276
277~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100278 Lesson 1.2.5: USING A COUNT TO DELETE MORE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279
280
Bram Moolenaar843ee412004-06-30 16:16:41 +0000281 ** Typing a number with an operator repeats it that many times. **
282
283 In the combination of the delete operator and a motion mentioned above you
284 insert a count before the motion to delete more:
285 d number motion
286
287 1. Move the cursor to the first UPPER CASE word in the line marked --->.
288
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200289 2. Type d2w to delete the two UPPER CASE words.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000290
291 3. Repeat steps 1 and 2 with a different count to delete the consecutive
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200292 UPPER CASE words with one command.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000293
294---> this ABC DE line FGHI JK LMN OP of words is Q RS TUV cleaned up.
295
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000296
297
Bram Moolenaar843ee412004-06-30 16:16:41 +0000298
299
300~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100301 Lesson 1.2.6: OPERATING ON LINES
Bram Moolenaar843ee412004-06-30 16:16:41 +0000302
303
304 ** Type dd to delete a whole line. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305
306 Due to the frequency of whole line deletion, the designers of Vi decided
Bram Moolenaar843ee412004-06-30 16:16:41 +0000307 it would be easier to simply type two d's to delete a line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308
309 1. Move the cursor to the second line in the phrase below.
310 2. Type dd to delete the line.
311 3. Now move to the fourth line.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000312 4. Type 2dd to delete two lines.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313
Bram Moolenaar843ee412004-06-30 16:16:41 +0000314---> 1) Roses are red,
315---> 2) Mud is fun,
316---> 3) Violets are blue,
317---> 4) I have a car,
318---> 5) Clocks tell time,
319---> 6) Sugar is sweet
320---> 7) And so are you.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000321
Bram Moolenaar4466ad62020-11-21 13:16:30 +0100322Doubling to operate on a line also works for operators mentioned below.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000323~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100324 Lesson 1.2.7: THE UNDO COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000325
326
Bram Moolenaar843ee412004-06-30 16:16:41 +0000327 ** Press u to undo the last commands, U to fix a whole line. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000328
329 1. Move the cursor to the line below marked ---> and place it on the
330 first error.
331 2. Type x to delete the first unwanted character.
332 3. Now type u to undo the last command executed.
333 4. This time fix all the errors on the line using the x command.
334 5. Now type a capital U to return the line to its original state.
335 6. Now type u a few times to undo the U and preceding commands.
336 7. Now type CTRL-R (keeping CTRL key pressed while hitting R) a few times
Bram Moolenaarbe4e0162023-02-02 13:59:48 +0000337 to redo the commands (undo the undos).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000338
339---> Fiix the errors oon thhis line and reeplace them witth undo.
340
RestorerZ6fa304f2024-12-02 20:19:52 +0100341 8. These are very useful commands. Now move on to the lesson 1.2 Summary.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000342
343
344
345
346~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100347 Lesson 1.2 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348
Bram Moolenaar34cc7d82021-09-21 20:09:51 +0200349 1. To delete from the cursor up to the next word type: dw
350 2. To delete from the cursor up to the end of the word type: de
351 3. To delete from the cursor to the end of a line type: d$
352 4. To delete a whole line type: dd
Bram Moolenaar071d4272004-06-13 20:20:40 +0000353
Bram Moolenaar34cc7d82021-09-21 20:09:51 +0200354 5. To repeat a motion prepend it with a number: 2w
355 6. The format for a change command is:
Bram Moolenaar843ee412004-06-30 16:16:41 +0000356 operator [number] motion
Bram Moolenaar071d4272004-06-13 20:20:40 +0000357 where:
Bram Moolenaar843ee412004-06-30 16:16:41 +0000358 operator - is what to do, such as d for delete
359 [number] - is an optional count to repeat the motion
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000360 motion - moves over the text to operate on, such as w (word),
Bram Moolenaar34cc7d82021-09-21 20:09:51 +0200361 e (end of word), $ (end of the line), etc.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362
Bram Moolenaar34cc7d82021-09-21 20:09:51 +0200363 7. To move to the start of the line use a zero: 0
Bram Moolenaar843ee412004-06-30 16:16:41 +0000364
Bram Moolenaar34cc7d82021-09-21 20:09:51 +0200365 8. To undo previous actions, type: u (lowercase u)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000366 To undo all the changes on a line, type: U (capital U)
Bram Moolenaarbe4e0162023-02-02 13:59:48 +0000367 To undo the undos, type: CTRL-R
Bram Moolenaar071d4272004-06-13 20:20:40 +0000368
369~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100370 Lesson 1.3.1: THE PUT COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000371
372
Bram Moolenaar843ee412004-06-30 16:16:41 +0000373 ** Type p to put previously deleted text after the cursor. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000374
Bram Moolenaarb477af22018-07-15 20:20:18 +0200375 1. Move the cursor to the first line below marked --->.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376
Bram Moolenaar843ee412004-06-30 16:16:41 +0000377 2. Type dd to delete the line and store it in a Vim register.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378
Bram Moolenaar843ee412004-06-30 16:16:41 +0000379 3. Move the cursor to the c) line, ABOVE where the deleted line should go.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380
Bram Moolenaar843ee412004-06-30 16:16:41 +0000381 4. Type p to put the line below the cursor.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382
383 5. Repeat steps 2 through 4 to put all the lines in correct order.
384
Bram Moolenaar843ee412004-06-30 16:16:41 +0000385---> d) Can you learn too?
386---> b) Violets are blue,
387---> c) Intelligence is learned,
388---> a) Roses are red,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000389
390
391
392~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100393 Lesson 1.3.2: THE REPLACE COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394
395
Bram Moolenaar843ee412004-06-30 16:16:41 +0000396 ** Type rx to replace the character at the cursor with x . **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397
398 1. Move the cursor to the first line below marked --->.
399
400 2. Move the cursor so that it is on top of the first error.
401
Bram Moolenaar843ee412004-06-30 16:16:41 +0000402 3. Type r and then the character which should be there.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000403
Bram Moolenaar843ee412004-06-30 16:16:41 +0000404 4. Repeat steps 2 and 3 until the first line is equal to the second one.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000405
406---> Whan this lime was tuoed in, someone presswd some wrojg keys!
407---> When this line was typed in, someone pressed some wrong keys!
408
RestorerZ6fa304f2024-12-02 20:19:52 +0100409 5. Now move on to lesson 1.3.3.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410
Bram Moolenaar843ee412004-06-30 16:16:41 +0000411NOTE: Remember that you should be learning by doing, not memorization.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000412
413
414
415~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100416 Lesson 1.3.3: THE CHANGE OPERATOR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000417
418
Bram Moolenaar843ee412004-06-30 16:16:41 +0000419 ** To change until the end of a word, type ce . **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000420
421 1. Move the cursor to the first line below marked --->.
422
Bram Moolenaar843ee412004-06-30 16:16:41 +0000423 2. Place the cursor on the u in lubw.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000424
Bram Moolenaar843ee412004-06-30 16:16:41 +0000425 3. Type ce and the correct word (in this case, type ine ).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426
Bram Moolenaar843ee412004-06-30 16:16:41 +0000427 4. Press <ESC> and move to the next character that needs to be changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000428
429 5. Repeat steps 3 and 4 until the first sentence is the same as the second.
430
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000431---> This lubw has a few wptfd that mrrf changing usf the change operator.
432---> This line has a few words that need changing using the change operator.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000433
Bram Moolenaar843ee412004-06-30 16:16:41 +0000434Notice that ce deletes the word and places you in Insert mode.
Bram Moolenaar4466ad62020-11-21 13:16:30 +0100435 cc does the same for the whole line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000436
437
438~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100439 Lesson 1.3.4: MORE CHANGES USING c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440
441
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000442 ** The change operator is used with the same motions as delete. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000443
Bram Moolenaar843ee412004-06-30 16:16:41 +0000444 1. The change operator works in the same way as delete. The format is:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000445
Bram Moolenaar843ee412004-06-30 16:16:41 +0000446 c [number] motion
Bram Moolenaar071d4272004-06-13 20:20:40 +0000447
Bram Moolenaar843ee412004-06-30 16:16:41 +0000448 2. The motions are the same, such as w (word) and $ (end of line).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449
Bram Moolenaarb477af22018-07-15 20:20:18 +0200450 3. Move the cursor to the first line below marked --->.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451
452 4. Move the cursor to the first error.
453
Bram Moolenaar843ee412004-06-30 16:16:41 +0000454 5. Type c$ and type the rest of the line like the second and press <ESC>.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000455
456---> The end of this line needs some help to make it like the second.
457---> The end of this line needs to be corrected using the c$ command.
458
Bram Moolenaar843ee412004-06-30 16:16:41 +0000459NOTE: You can use the Backspace key to correct mistakes while typing.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000460
461~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100462 Lesson 1.3 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000463
464
Bram Moolenaar843ee412004-06-30 16:16:41 +0000465 1. To put back text that has just been deleted, type p . This puts the
Bram Moolenaar071d4272004-06-13 20:20:40 +0000466 deleted text AFTER the cursor (if a line was deleted it will go on the
467 line below the cursor).
468
469 2. To replace the character under the cursor, type r and then the
Bram Moolenaar843ee412004-06-30 16:16:41 +0000470 character you want to have there.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000471
Bram Moolenaar843ee412004-06-30 16:16:41 +0000472 3. The change operator allows you to change from the cursor to where the
473 motion takes you. eg. Type ce to change from the cursor to the end of
474 the word, c$ to change to the end of a line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000475
476 4. The format for change is:
477
Bram Moolenaar843ee412004-06-30 16:16:41 +0000478 c [number] motion
Bram Moolenaar071d4272004-06-13 20:20:40 +0000479
480Now go on to the next lesson.
481
482
483
484~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100485 Lesson 1.4.1: CURSOR LOCATION AND FILE STATUS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000486
Bram Moolenaar843ee412004-06-30 16:16:41 +0000487 ** Type CTRL-G to show your location in the file and the file status.
488 Type G to move to a line in the file. **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000490 NOTE: Read this entire lesson before executing any of the steps!!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000491
Bram Moolenaar843ee412004-06-30 16:16:41 +0000492 1. Hold down the Ctrl key and press g . We call this CTRL-G.
493 A message will appear at the bottom of the page with the filename and the
494 position in the file. Remember the line number for Step 3.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000495
Bram Moolenaar843ee412004-06-30 16:16:41 +0000496NOTE: You may see the cursor position in the lower right corner of the screen
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000497 This happens when the 'ruler' option is set (see :help 'ruler' )
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498
Bram Moolenaar843ee412004-06-30 16:16:41 +0000499 2. Press G to move you to the bottom of the file.
500 Type gg to move you to the start of the file.
501
502 3. Type the number of the line you were on and then G . This will
503 return you to the line you were on when you first pressed CTRL-G.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504
505 4. If you feel confident to do this, execute steps 1 through 3.
506
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100508 Lesson 1.4.2: THE SEARCH COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509
510
511 ** Type / followed by a phrase to search for the phrase. **
512
513 1. In Normal mode type the / character. Notice that it and the cursor
514 appear at the bottom of the screen as with the : command.
515
516 2. Now type 'errroor' <ENTER>. This is the word you want to search for.
517
518 3. To search for the same phrase again, simply type n .
Bram Moolenaar843ee412004-06-30 16:16:41 +0000519 To search for the same phrase in the opposite direction, type N .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520
Bram Moolenaar843ee412004-06-30 16:16:41 +0000521 4. To search for a phrase in the backward direction, use ? instead of / .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522
Bram Moolenaar843ee412004-06-30 16:16:41 +0000523 5. To go back to where you came from press CTRL-O (Keep Ctrl down while
524 pressing the letter o). Repeat to go back further. CTRL-I goes forward.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000526---> "errroor" is not the way to spell error; errroor is an error.
527NOTE: When the search reaches the end of the file it will continue at the
Bram Moolenaar843ee412004-06-30 16:16:41 +0000528 start, unless the 'wrapscan' option has been reset.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529
530~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100531 Lesson 1.4.3: MATCHING PARENTHESES SEARCH
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532
533
534 ** Type % to find a matching ),], or } . **
535
536 1. Place the cursor on any (, [, or { in the line below marked --->.
537
538 2. Now type the % character.
539
Bram Moolenaar843ee412004-06-30 16:16:41 +0000540 3. The cursor will move to the matching parenthesis or bracket.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000541
Bram Moolenaar843ee412004-06-30 16:16:41 +0000542 4. Type % to move the cursor to the other matching bracket.
543
544 5. Move the cursor to another (,),[,],{ or } and see what % does.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545
546---> This ( is a test line with ('s, ['s ] and {'s } in it. ))
547
Bram Moolenaar843ee412004-06-30 16:16:41 +0000548
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000549NOTE: This is very useful in debugging a program with unmatched parentheses!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550
551
552
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100554 Lesson 1.4.4: THE SUBSTITUTE COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555
556
557 ** Type :s/old/new/g to substitute 'new' for 'old'. **
558
559 1. Move the cursor to the line below marked --->.
560
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200561 2. Type :s/thee/the <ENTER> . Note that this command only changes the
Bram Moolenaar843ee412004-06-30 16:16:41 +0000562 first occurrence of "thee" in the line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563
Bram Moolenaar843ee412004-06-30 16:16:41 +0000564 3. Now type :s/thee/the/g . Adding the g flag means to substitute
565 globally in the line, change all occurrences of "thee" in the line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566
567---> thee best time to see thee flowers is in thee spring.
568
569 4. To change every occurrence of a character string between two lines,
Bram Moolenaar843ee412004-06-30 16:16:41 +0000570 type :#,#s/old/new/g where #,# are the line numbers of the range
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000571 of lines where the substitution is to be done.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000572 Type :%s/old/new/g to change every occurrence in the whole file.
573 Type :%s/old/new/gc to find every occurrence in the whole file,
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000574 with a prompt whether to substitute or not.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575
576~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100577 Lesson 1.4 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578
579
Bram Moolenaar843ee412004-06-30 16:16:41 +0000580 1. CTRL-G displays your location in the file and the file status.
581 G moves to the end of the file.
582 number G moves to that line number.
583 gg moves to the first line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584
585 2. Typing / followed by a phrase searches FORWARD for the phrase.
586 Typing ? followed by a phrase searches BACKWARD for the phrase.
587 After a search type n to find the next occurrence in the same direction
Bram Moolenaar843ee412004-06-30 16:16:41 +0000588 or N to search in the opposite direction.
589 CTRL-O takes you back to older positions, CTRL-I to newer positions.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590
Bram Moolenaar843ee412004-06-30 16:16:41 +0000591 3. Typing % while the cursor is on a (,),[,],{, or } goes to its match.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592
Bram Moolenaar843ee412004-06-30 16:16:41 +0000593 4. To substitute new for the first old in a line type :s/old/new
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 To substitute new for all 'old's on a line type :s/old/new/g
595 To substitute phrases between two line #'s type :#,#s/old/new/g
596 To substitute all occurrences in the file type :%s/old/new/g
597 To ask for confirmation each time add 'c' :%s/old/new/gc
598
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100600 Lesson 1.5.1: HOW TO EXECUTE AN EXTERNAL COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601
602
603 ** Type :! followed by an external command to execute that command. **
604
605 1. Type the familiar command : to set the cursor at the bottom of the
Bram Moolenaar843ee412004-06-30 16:16:41 +0000606 screen. This allows you to enter a command-line command.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607
608 2. Now type the ! (exclamation point) character. This allows you to
609 execute any external shell command.
610
611 3. As an example type ls following the ! and then hit <ENTER>. This
612 will show you a listing of your directory, just as if you were at the
Bram Moolenaar843ee412004-06-30 16:16:41 +0000613 shell prompt. Or use :!dir if ls doesn't work.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000615NOTE: It is possible to execute any external command this way, also with
Bram Moolenaar843ee412004-06-30 16:16:41 +0000616 arguments.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000618NOTE: All : commands must be finished by hitting <ENTER>
619 From here on we will not always mention it.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000620
621
622~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100623 Lesson 1.5.2: MORE ON WRITING FILES
Bram Moolenaar071d4272004-06-13 20:20:40 +0000624
625
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200626 ** To save the changes made to the text, type :w FILENAME **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627
628 1. Type :!dir or :!ls to get a listing of your directory.
629 You already know you must hit <ENTER> after this.
630
631 2. Choose a filename that does not exist yet, such as TEST.
632
633 3. Now type: :w TEST (where TEST is the filename you chose.)
634
Bram Moolenaar843ee412004-06-30 16:16:41 +0000635 4. This saves the whole file (the Vim Tutor) under the name TEST.
636 To verify this, type :!dir or :!ls again to see your directory.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000638NOTE: If you were to exit Vim and start it again with vim TEST , the file
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 would be an exact copy of the tutor when you saved it.
640
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200641 5. Now remove the file by typing (Windows): :!del TEST
Bram Moolenaar071d4272004-06-13 20:20:40 +0000642 or (Unix): :!rm TEST
643
644
645~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100646 Lesson 1.5.3: SELECTING TEXT TO WRITE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000647
648
Bram Moolenaar843ee412004-06-30 16:16:41 +0000649 ** To save part of the file, type v motion :w FILENAME **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000650
Bram Moolenaar843ee412004-06-30 16:16:41 +0000651 1. Move the cursor to this line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000652
Bram Moolenaar843ee412004-06-30 16:16:41 +0000653 2. Press v and move the cursor to the fifth item below. Notice that the
654 text is highlighted.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000655
Bram Moolenaar843ee412004-06-30 16:16:41 +0000656 3. Press the : character. At the bottom of the screen :'<,'> will appear.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000657
Bram Moolenaar843ee412004-06-30 16:16:41 +0000658 4. Type w TEST , where TEST is a filename that does not exist yet. Verify
Bram Moolenaar59c03952010-07-28 12:52:27 +0200659 that you see :'<,'>w TEST before you press <ENTER>.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660
Bram Moolenaar97cc2382012-10-03 21:46:54 +0200661 5. Vim will write the selected lines to the file TEST. Use :!dir or :!ls
Bram Moolenaar843ee412004-06-30 16:16:41 +0000662 to see it. Do not remove it yet! We will use it in the next lesson.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663
Bram Moolenaar843ee412004-06-30 16:16:41 +0000664NOTE: Pressing v starts Visual selection. You can move the cursor around
665 to make the selection bigger or smaller. Then you can use an operator
666 to do something with the text. For example, d deletes the text.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667
668~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100669 Lesson 1.5.4: RETRIEVING AND MERGING FILES
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670
671
Bram Moolenaar843ee412004-06-30 16:16:41 +0000672 ** To insert the contents of a file, type :r FILENAME **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673
Bram Moolenaar843ee412004-06-30 16:16:41 +0000674 1. Place the cursor just above this line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675
RestorerZ6fa304f2024-12-02 20:19:52 +0100676NOTE: After executing Step 2 you will see text from lesson 1.5.3. Then move
Bram Moolenaar843ee412004-06-30 16:16:41 +0000677 DOWN to see this lesson again.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678
Bram Moolenaar843ee412004-06-30 16:16:41 +0000679 2. Now retrieve your TEST file using the command :r TEST where TEST is
680 the name of the file you used.
681 The file you retrieve is placed below the cursor line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682
Bram Moolenaar843ee412004-06-30 16:16:41 +0000683 3. To verify that a file was retrieved, cursor back and notice that there
RestorerZ6fa304f2024-12-02 20:19:52 +0100684 are now two copies of lesson 1.5.3, the original and the file version.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000685
Bram Moolenaar843ee412004-06-30 16:16:41 +0000686NOTE: You can also read the output of an external command. For example,
687 :r !ls reads the output of the ls command and puts it below the
688 cursor.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000689
690
691~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100692 Lesson 1.5 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000693
694
695 1. :!command executes an external command.
696
697 Some useful examples are:
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200698 (Windows) (Unix)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000699 :!dir :!ls - shows a directory listing.
700 :!del FILENAME :!rm FILENAME - removes file FILENAME.
701
702 2. :w FILENAME writes the current Vim file to disk with name FILENAME.
703
Bram Moolenaar843ee412004-06-30 16:16:41 +0000704 3. v motion :w FILENAME saves the Visually selected lines in file
705 FILENAME.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706
Bram Moolenaar843ee412004-06-30 16:16:41 +0000707 4. :r FILENAME retrieves disk file FILENAME and puts it below the
708 cursor position.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709
Bram Moolenaar843ee412004-06-30 16:16:41 +0000710 5. :r !dir reads the output of the dir command and puts it below the
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000711 cursor position.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712
713
714~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100715 Lesson 1.6.1: THE OPEN COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716
717
718 ** Type o to open a line below the cursor and place you in Insert mode. **
719
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200720 1. Move the cursor to the first line below marked --->.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721
Bram Moolenaar843ee412004-06-30 16:16:41 +0000722 2. Type the lowercase letter o to open up a line BELOW the cursor and place
723 you in Insert mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724
Bram Moolenaar843ee412004-06-30 16:16:41 +0000725 3. Now type some text and press <ESC> to exit Insert mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726
727---> After typing o the cursor is placed on the open line in Insert mode.
728
729 4. To open up a line ABOVE the cursor, simply type a capital O , rather
730 than a lowercase o. Try this on the line below.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731
Bram Moolenaar843ee412004-06-30 16:16:41 +0000732---> Open up a line above this by typing O while the cursor is on this line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733
734
735
736
737~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100738 Lesson 1.6.2: THE APPEND COMMAND
Bram Moolenaar071d4272004-06-13 20:20:40 +0000739
740
741 ** Type a to insert text AFTER the cursor. **
742
Bram Moolenaarb477af22018-07-15 20:20:18 +0200743 1. Move the cursor to the start of the first line below marked --->.
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200744
Bram Moolenaar843ee412004-06-30 16:16:41 +0000745 2. Press e until the cursor is on the end of li .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000746
Bram Moolenaar843ee412004-06-30 16:16:41 +0000747 3. Type an a (lowercase) to append text AFTER the cursor.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748
Bram Moolenaar843ee412004-06-30 16:16:41 +0000749 4. Complete the word like the line below it. Press <ESC> to exit Insert
750 mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751
Bram Moolenaar843ee412004-06-30 16:16:41 +0000752 5. Use e to move to the next incomplete word and repeat steps 3 and 4.
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200753
Bram Moolenaar843ee412004-06-30 16:16:41 +0000754---> This li will allow you to pract appendi text to a line.
755---> This line will allow you to practice appending text to a line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000757NOTE: a, i and A all go to the same Insert mode, the only difference is where
Bram Moolenaar843ee412004-06-30 16:16:41 +0000758 the characters are inserted.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000759
760~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100761 Lesson 1.6.3: ANOTHER WAY TO REPLACE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762
763
764 ** Type a capital R to replace more than one character. **
765
Bram Moolenaar843ee412004-06-30 16:16:41 +0000766 1. Move the cursor to the first line below marked --->. Move the cursor to
767 the beginning of the first xxx .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768
Bram Moolenaar843ee412004-06-30 16:16:41 +0000769 2. Now press R and type the number below it in the second line, so that it
770 replaces the xxx .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771
Bram Moolenaar843ee412004-06-30 16:16:41 +0000772 3. Press <ESC> to leave Replace mode. Notice that the rest of the line
773 remains unmodified.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000775 4. Repeat the steps to replace the remaining xxx.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776
Bram Moolenaar843ee412004-06-30 16:16:41 +0000777---> Adding 123 to xxx gives you xxx.
778---> Adding 123 to 456 gives you 579.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000779
Bram Moolenaar843ee412004-06-30 16:16:41 +0000780NOTE: Replace mode is like Insert mode, but every typed character deletes an
781 existing character.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782
783~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100784 Lesson 1.6.4: COPY AND PASTE TEXT
Bram Moolenaar843ee412004-06-30 16:16:41 +0000785
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000786 ** Use the y operator to copy text and p to paste it **
Bram Moolenaar843ee412004-06-30 16:16:41 +0000787
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200788 1. Move to the line below marked ---> and place the cursor after "a)".
789
Bram Moolenaar843ee412004-06-30 16:16:41 +0000790 2. Start Visual mode with v and move the cursor to just before "first".
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200791
Bram Moolenaar843ee412004-06-30 16:16:41 +0000792 3. Type y to yank (copy) the highlighted text.
793
794 4. Move the cursor to the end of the next line: j$
795
796 5. Type p to put (paste) the text. Then type: a second <ESC> .
797
798 6. Use Visual mode to select " item.", yank it with y , move to the end of
799 the next line with j$ and put the text there with p .
800
801---> a) this is the first item.
802 b)
803
Bram Moolenaar1c6737b2020-09-07 22:18:52 +0200804 NOTE: You can also use y as an operator: yw yanks one word,
Bram Moolenaar4466ad62020-11-21 13:16:30 +0100805 yy yanks the whole line, then p puts that line.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000806~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100807 Lesson 1.6.5: SET OPTION
Bram Moolenaar843ee412004-06-30 16:16:41 +0000808
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809
810 ** Set an option so a search or substitute ignores case **
811
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200812 1. Search for 'ignore' by entering: /ignore <ENTER>
Bram Moolenaar843ee412004-06-30 16:16:41 +0000813 Repeat several times by pressing n .
Bram Moolenaar071d4272004-06-13 20:20:40 +0000814
Bram Moolenaar843ee412004-06-30 16:16:41 +0000815 2. Set the 'ic' (Ignore case) option by entering: :set ic
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816
Bram Moolenaar843ee412004-06-30 16:16:41 +0000817 3. Now search for 'ignore' again by pressing n
818 Notice that Ignore and IGNORE are now also found.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819
Bram Moolenaar843ee412004-06-30 16:16:41 +0000820 4. Set the 'hlsearch' and 'incsearch' options: :set hls is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000821
Bram Moolenaar843ee412004-06-30 16:16:41 +0000822 5. Now type the search command again and see what happens: /ignore <ENTER>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823
Bram Moolenaar843ee412004-06-30 16:16:41 +0000824 6. To disable ignoring case enter: :set noic
825
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200826NOTE: To remove the highlighting of matches enter: :nohlsearch
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000827NOTE: If you want to ignore case for just one search command, use \c
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200828 in the phrase: /ignore\c <ENTER>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000829~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100830 Lesson 1.6 SUMMARY
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831
Bram Moolenaar843ee412004-06-30 16:16:41 +0000832 1. Type o to open a line BELOW the cursor and start Insert mode.
833 Type O to open a line ABOVE the cursor.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000834
Bram Moolenaar843ee412004-06-30 16:16:41 +0000835 2. Type a to insert text AFTER the cursor.
836 Type A to insert text after the end of the line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837
Bram Moolenaar843ee412004-06-30 16:16:41 +0000838 3. The e command moves to the end of a word.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000839
Bram Moolenaar843ee412004-06-30 16:16:41 +0000840 4. The y operator yanks (copies) text, p puts (pastes) it.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841
Bram Moolenaar843ee412004-06-30 16:16:41 +0000842 5. Typing a capital R enters Replace mode until <ESC> is pressed.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843
Bram Moolenaar843ee412004-06-30 16:16:41 +0000844 6. Typing ":set xxx" sets the option "xxx". Some options are:
845 'ic' 'ignorecase' ignore upper/lower case when searching
846 'is' 'incsearch' show partial matches for a search phrase
847 'hls' 'hlsearch' highlight all matching phrases
848 You can either use the long or the short option name.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849
Bram Moolenaar843ee412004-06-30 16:16:41 +0000850 7. Prepend "no" to switch an option off: :set noic
Bram Moolenaar071d4272004-06-13 20:20:40 +0000851
852~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100853 Lesson 1.7.1: GETTING HELP
Bram Moolenaar071d4272004-06-13 20:20:40 +0000854
855
856 ** Use the on-line help system **
857
858 Vim has a comprehensive on-line help system. To get started, try one of
859 these three:
860 - press the <HELP> key (if you have one)
861 - press the <F1> key (if you have one)
862 - type :help <ENTER>
863
Bram Moolenaar843ee412004-06-30 16:16:41 +0000864 Read the text in the help window to find out how the help works.
Bram Moolenaar756ec0f2007-05-05 17:59:48 +0000865 Type CTRL-W CTRL-W to jump from one window to another.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000866 Type :q <ENTER> to close the help window.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000867
868 You can find help on just about any subject, by giving an argument to the
869 ":help" command. Try these (don't forget pressing <ENTER>):
870
871 :help w
Bram Moolenaar843ee412004-06-30 16:16:41 +0000872 :help c_CTRL-D
Bram Moolenaar071d4272004-06-13 20:20:40 +0000873 :help insert-index
874 :help user-manual
Bram Moolenaar071d4272004-06-13 20:20:40 +0000875~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100876 Lesson 1.7.2: CREATE A STARTUP SCRIPT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000877
Bram Moolenaar071d4272004-06-13 20:20:40 +0000878
Bram Moolenaar843ee412004-06-30 16:16:41 +0000879 ** Enable Vim features **
Bram Moolenaar071d4272004-06-13 20:20:40 +0000880
Bram Moolenaar843ee412004-06-30 16:16:41 +0000881 Vim has many more features than Vi, but most of them are disabled by
Bram Moolenaard2ea7cf2021-05-30 20:54:13 +0200882 default. To start using more features you should create a "vimrc" file.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883
Bram Moolenaar843ee412004-06-30 16:16:41 +0000884 1. Start editing the "vimrc" file. This depends on your system:
885 :e ~/.vimrc for Unix
Bram Moolenaard2ea7cf2021-05-30 20:54:13 +0200886 :e ~/_vimrc for Windows
Bram Moolenaar071d4272004-06-13 20:20:40 +0000887
Bram Moolenaar843ee412004-06-30 16:16:41 +0000888 2. Now read the example "vimrc" file contents:
889 :r $VIMRUNTIME/vimrc_example.vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890
891 3. Write the file with:
Bram Moolenaar843ee412004-06-30 16:16:41 +0000892 :w
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893
894 The next time you start Vim it will use syntax highlighting.
895 You can add all your preferred settings to this "vimrc" file.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000896 For more information type :help vimrc-intro
897
898~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100899 Lesson 1.7.3: COMPLETION
Bram Moolenaar843ee412004-06-30 16:16:41 +0000900
901
902 ** Command line completion with CTRL-D and <TAB> **
903
904 1. Make sure Vim is not in compatible mode: :set nocp
905
906 2. Look what files exist in the directory: :!ls or :!dir
907
908 3. Type the start of a command: :e
909
910 4. Press CTRL-D and Vim will show a list of commands that start with "e".
911
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200912 5. Type d<TAB> and Vim will complete the command name to ":edit".
Bram Moolenaar843ee412004-06-30 16:16:41 +0000913
914 6. Now add a space and the start of an existing file name: :edit FIL
915
916 7. Press <TAB>. Vim will complete the name (if it is unique).
917
918NOTE: Completion works for many commands. Just try pressing CTRL-D and
919 <TAB>. It is especially useful for :help .
920
921~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RestorerZ6fa304f2024-12-02 20:19:52 +0100922 Lesson 1.7 SUMMARY
Bram Moolenaar843ee412004-06-30 16:16:41 +0000923
924
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200925 1. Type :help or press <F1> or <HELP> to open a help window.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000926
927 2. Type :help cmd to find help on cmd .
928
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200929 3. Type CTRL-W CTRL-W to jump to another window.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000930
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200931 4. Type :q to close the help window.
Bram Moolenaar843ee412004-06-30 16:16:41 +0000932
933 5. Create a vimrc startup script to keep your preferred settings.
934
935 6. When typing a : command, press CTRL-D to see possible completions.
936 Press <TAB> to use one completion.
937
938
939
940
941
942
Bram Moolenaar071d4272004-06-13 20:20:40 +0000943
944~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
945
Ken Takatab183f502024-12-19 20:03:10 +0100946 This concludes Chapter 1 of the Vim Tutor. Consider continuing with
947 Chapter 2.
Paul Desmond Parker17c71da2024-11-03 20:47:53 +0100948
949 It was intended to give a brief overview of the Vim editor, just enough to
950 allow you to use the editor fairly easily. It is far from complete as Vim
951 has many many more commands.
952
953 Read the user manual next: ":help user-manual".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000954
955 For further reading and studying, this book is recommended:
956 Vim - Vi Improved - by Steve Oualline
957 Publisher: New Riders
958 The first book completely dedicated to Vim. Especially useful for beginners.
959 There are many examples and pictures.
Bram Moolenaar9da17d72022-02-09 21:50:44 +0000960 See https://iccf-holland.org/click5.html
Bram Moolenaar071d4272004-06-13 20:20:40 +0000961
962 This book is older and more about Vi than Vim, but also recommended:
963 Learning the Vi Editor - by Linda Lamb
964 Publisher: O'Reilly & Associates Inc.
965 It is a good book to get to know almost anything you want to do with Vi.
966 The sixth edition also includes information on Vim.
967
968 This tutorial was written by Michael C. Pierce and Robert K. Ware,
969 Colorado School of Mines using ideas supplied by Charles Smith,
970 Colorado State University. E-mail: bware@mines.colorado.edu.
971
972 Modified for Vim by Bram Moolenaar.
973
974~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~