Mercurial > vim
comparison runtime/tutor/tutor @ 11:4424b47a0797
updated for version 7.0003
author | vimboss |
---|---|
date | Wed, 30 Jun 2004 16:16:41 +0000 |
parents | 3fc0f57ecb91 |
children | c4cd8ad60bee |
comparison
equal
deleted
inserted
replaced
10:4e2284e71352 | 11:4424b47a0797 |
---|---|
1 =============================================================================== | 1 =============================================================================== |
2 = W e l c o m e t o t h e V I M T u t o r - Version 1.5 = | 2 = W e l c o m e t o t h e V I M T u t o r - Version 1.7 = |
3 =============================================================================== | 3 =============================================================================== |
4 | 4 |
5 Vim is a very powerful editor that has many commands, too many to | 5 Vim is a very powerful editor that has many commands, too many to |
6 explain in a tutor such as this. This tutor is designed to describe | 6 explain in a tutor such as this. This tutor is designed to describe |
7 enough of the commands that you will be able to easily use Vim as | 7 enough of the commands that you will be able to easily use Vim as |
8 an all-purpose editor. | 8 an all-purpose editor. |
9 | 9 |
10 The approximate time required to complete the tutor is 25-30 minutes, | 10 The approximate time required to complete the tutor is 25-30 minutes, |
11 depending upon how much time is spent with experimentation. | 11 depending upon how much time is spent with experimentation. |
12 | 12 |
13 ATTENTION: | |
13 The commands in the lessons will modify the text. Make a copy of this | 14 The commands in the lessons will modify the text. Make a copy of this |
14 file to practise on (if you started "vimtutor" this is already a copy). | 15 file to practise on (if you started "vimtutor" this is already a copy). |
15 | 16 |
16 It is important to remember that this tutor is set up to teach by | 17 It is important to remember that this tutor is set up to teach by |
17 use. That means that you need to execute the commands to learn them | 18 use. That means that you need to execute the commands to learn them |
31 j The j key looks like a down arrow | 32 j The j key looks like a down arrow |
32 v | 33 v |
33 1. Move the cursor around the screen until you are comfortable. | 34 1. Move the cursor around the screen until you are comfortable. |
34 | 35 |
35 2. Hold down the down key (j) until it repeats. | 36 2. Hold down the down key (j) until it repeats. |
36 ---> Now you know how to move to the next lesson. | 37 Now you know how to move to the next lesson. |
37 | 38 |
38 3. Using the down key, move to Lesson 1.2. | 39 3. Using the down key, move to Lesson 1.2. |
39 | 40 |
40 Note: If you are ever unsure about something you typed, press <ESC> to place | 41 Note: If you are ever unsure about something you typed, press <ESC> to place |
41 you in Normal mode. Then retype the command you wanted. | 42 you in Normal mode. Then retype the command you wanted. |
42 | 43 |
43 Note: The cursor keys should also work. But using hjkl you will be able to | 44 Note: The cursor keys should also work. But using hjkl you will be able to |
44 move around much faster, once you get used to it. | 45 move around much faster, once you get used to it. Really! |
45 | 46 |
46 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 47 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
47 Lesson 1.2: ENTERING AND EXITING VIM | 48 Lesson 1.2: EXITING VIM |
48 | 49 |
49 | 50 |
50 !! NOTE: Before executing any of the steps below, read this entire lesson!! | 51 !! NOTE: Before executing any of the steps below, read this entire lesson!! |
51 | 52 |
52 1. Press the <ESC> key (to make sure you are in Normal mode). | 53 1. Press the <ESC> key (to make sure you are in Normal mode). |
53 | 54 |
54 2. Type: :q! <ENTER>. | 55 2. Type: :q! <ENTER>. |
55 | 56 This exits the editor, DISCARDING any changes you have made. |
56 ---> This exits the editor WITHOUT saving any changes you have made. | |
57 If you want to save the changes and exit type: | |
58 :wq <ENTER> | |
59 | 57 |
60 3. When you see the shell prompt, type the command that got you into this | 58 3. When you see the shell prompt, type the command that got you into this |
61 tutor. That could be: vimtutor <ENTER> | 59 tutor. That would be: vimtutor <ENTER> |
62 Normally you would use: vim tutor <ENTER> | |
63 | |
64 ---> 'vim' means enter the vim editor, 'tutor' is the file you wish to edit. | |
65 | 60 |
66 4. If you have these steps memorized and are confident, execute steps | 61 4. If you have these steps memorized and are confident, execute steps |
67 1 through 3 to exit and re-enter the editor. Then move the cursor down | 62 1 through 3 to exit and re-enter the editor. |
68 to Lesson 1.3. | 63 |
64 NOTE: :q! <ENTER> discards any changes you made. In a few lessons you | |
65 will learn how to save the changes to a file. | |
66 | |
67 5. Move the cursor down to Lesson 1.3. | |
68 | |
69 | |
69 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 70 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
70 Lesson 1.3: TEXT EDITING - DELETION | 71 Lesson 1.3: TEXT EDITING - DELETION |
71 | 72 |
72 | 73 |
73 ** While in Normal mode press x to delete the character under the cursor. ** | 74 ** Press x to delete the character under the cursor. ** |
74 | 75 |
75 1. Move the cursor to the line below marked --->. | 76 1. Move the cursor to the line below marked --->. |
76 | 77 |
77 2. To fix the errors, move the cursor until it is on top of the | 78 2. To fix the errors, move the cursor until it is on top of the |
78 character to be deleted. | 79 character to be deleted. |
88 NOTE: As you go through this tutor, do not try to memorize, learn by usage. | 89 NOTE: As you go through this tutor, do not try to memorize, learn by usage. |
89 | 90 |
90 | 91 |
91 | 92 |
92 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 93 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
93 Lesson 1.4: TEXT EDITING - INSERTION | 94 Lesson 1.4: TEXT EDITING - INSERTION |
94 | 95 |
95 | 96 |
96 ** While in Normal mode press i to insert text. ** | 97 ** Press i to insert text. ** |
97 | 98 |
98 1. Move the cursor to the first line below marked --->. | 99 1. Move the cursor to the first line below marked --->. |
99 | 100 |
100 2. To make the first line the same as the second, move the cursor on top | 101 2. To make the first line the same as the second, move the cursor on top |
101 of the first character AFTER where the text is to be inserted. | 102 of the first character AFTER where the text is to be inserted. |
111 5. When you are comfortable inserting text move to the summary below. | 112 5. When you are comfortable inserting text move to the summary below. |
112 | 113 |
113 | 114 |
114 | 115 |
115 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 116 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
117 Lesson 1.5: TEXT EDITING - APPENDING | |
118 | |
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 | |
129 4. Move the cursor to the second line marked ---> and repeat | |
130 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 | |
137 5. When you are comfortable appending text move to lesson 1.6. | |
138 | |
139 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
140 Lesson 1.6: EDITING A FILE | |
141 | |
142 | |
143 ** Use :wq to save a file and exit. ** | |
144 | |
145 !! NOTE: Before executing any of the steps below, read this entire lesson!! | |
146 | |
147 1. Exit this tutor as you did in lesson 1.2: :q! | |
148 | |
149 2. At the shell prompt type this command: vim tutor <ENTER> | |
150 'vim' is the command to start the Vim editor, 'tutor' is the name of the | |
151 file you wish to edit. Use a file that may be changed. | |
152 | |
153 3. Insert and delete text as you learned in the previous lessons. | |
154 | |
155 4. Save the file with changes and exit Vim with: :wq <ENTER> | |
156 | |
157 5. Restart the vimtutor and move down to the following summary. | |
158 | |
159 6. After reading the above steps and understanding them: do it. | |
160 | |
161 | |
162 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
116 LESSON 1 SUMMARY | 163 LESSON 1 SUMMARY |
117 | 164 |
118 | 165 |
119 1. The cursor is moved using either the arrow keys or the hjkl keys. | 166 1. The cursor is moved using either the arrow keys or the hjkl keys. |
120 h (left) j (down) k (up) l (right) | 167 h (left) j (down) k (up) l (right) |
121 | 168 |
122 2. To enter Vim (from the % prompt) type: vim FILENAME <ENTER> | 169 2. To start Vim from the shell prompt type: vim FILENAME <ENTER> |
123 | 170 |
124 3. To exit Vim type: <ESC> :q! <ENTER> to trash all changes. | 171 3. To exit Vim type: <ESC> :q! <ENTER> to trash all changes. |
125 OR type: <ESC> :wq <ENTER> to save the changes. | 172 OR type: <ESC> :wq <ENTER> to save the changes. |
126 | 173 |
127 4. To delete a character under the cursor in Normal mode type: x | 174 4. To delete the character at the cursor type: x |
128 | 175 |
129 5. To insert text at the cursor while in Normal mode type: | 176 5. To insert or append text type: |
130 i type in text <ESC> | 177 i type inserted text <ESC> insert before the cursor |
178 A type appended text <ESC> append after the line | |
131 | 179 |
132 NOTE: Pressing <ESC> will place you in Normal mode or will cancel | 180 NOTE: Pressing <ESC> will place you in Normal mode or will cancel |
133 an unwanted and partially completed command. | 181 an unwanted and partially completed command. |
134 | 182 |
135 Now continue with Lesson 2. | 183 Now continue with Lesson 2. |
136 | 184 |
137 | |
138 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 185 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
139 Lesson 2.1: DELETION COMMANDS | 186 Lesson 2.1: DELETION COMMANDS |
140 | 187 |
141 | 188 |
142 ** Type dw to delete to the end of a word. ** | 189 ** Type dw to delete a word. ** |
143 | 190 |
144 1. Press <ESC> to make sure you are in Normal mode. | 191 1. Press <ESC> to make sure you are in Normal mode. |
145 | 192 |
146 2. Move the cursor to the line below marked --->. | 193 2. Move the cursor to the line below marked --->. |
147 | 194 |
148 3. Move the cursor to the beginning of a word that needs to be deleted. | 195 3. Move the cursor to the beginning of a word that needs to be deleted. |
149 | 196 |
150 4. Type dw to make the word disappear. | 197 4. Type dw to make the word disappear. |
151 | 198 |
152 NOTE: The letters dw will appear on the last line of the screen as you type | 199 NOTE: The letter d will appear on the last line of the screen as you type |
153 them. If you typed something wrong, press <ESC> and start over. | 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. | |
154 | 202 |
155 ---> There are a some words fun that don't belong paper in this sentence. | 203 ---> There are a some words fun that don't belong paper in this sentence. |
156 | 204 |
157 5. Repeat steps 3 and 4 until the sentence is correct and go to Lesson 2.2. | 205 5. Repeat steps 3 and 4 until the sentence is correct and go to Lesson 2.2. |
158 | 206 |
159 | 207 |
160 | |
161 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 208 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
162 Lesson 2.2: MORE DELETION COMMANDS | 209 Lesson 2.2: MORE DELETION COMMANDS |
163 | 210 |
164 | 211 |
165 ** Type d$ to delete to the end of the line. ** | 212 ** Type d$ to delete to the end of the line. ** |
180 | 227 |
181 | 228 |
182 | 229 |
183 | 230 |
184 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 231 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
185 Lesson 2.3: ON COMMANDS AND OBJECTS | 232 Lesson 2.3: ON OPERATORS AND MOTIONS |
186 | 233 |
187 | 234 |
188 The format for the d delete command is as follows: | 235 Many commands that change text are made from an operator and a motion. |
189 | 236 The format for a delete command with the d delete operator is as follows: |
190 [number] d object OR d [number] object | 237 |
238 d motion | |
239 | |
191 Where: | 240 Where: |
192 number - is how many times to execute the command (optional, default=1). | 241 d - is the delete operator. |
193 d - is the command to delete. | 242 motion - is what the operator will operate on (listed below). |
194 object - is what the command will operate on (listed below). | 243 |
195 | 244 A short list of motions: |
196 A short list of objects: | 245 w - until the start of the next word, EXCLUDING its first character. |
197 w - from the cursor to the end of the word, including the space. | 246 e - to the end of the current word, INCLUDING the last character. |
198 e - from the cursor to the end of the word, NOT including the space. | 247 $ - to the end of the line, INCLUDING the last character. |
199 $ - from the cursor to the end of the line. | 248 |
200 | 249 Thus typing de will delete from the cursor to the end of the word. |
201 NOTE: For the adventurous, pressing just the object while in Normal mode | 250 |
202 without a command will move the cursor as specified in the object list. | 251 NOTE: Pressing just the motion while in Normal mode without an operator will |
203 | 252 move the cursor as specified. |
204 | 253 |
205 | 254 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
206 | 255 Lesson 2.4: USING A COUNT FOR A MOTION |
207 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 256 |
208 Lesson 2.4: AN EXCEPTION TO 'COMMAND-OBJECT' | 257 |
209 | 258 ** Typing a number before a motion repeats it that many times. ** |
210 | 259 |
211 ** Type dd to delete a whole line. ** | 260 1. Move the cursor to the start of the line marked ---> below. |
261 | |
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 | |
272 6. Move on to Lesson 2.5. | |
273 | |
274 | |
275 | |
276 | |
277 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
278 Lesson 2.5: USING A COUNT TO DELETE MORE | |
279 | |
280 | |
281 ** 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 | |
289 2. Type 2dw to delete the two UPPER CASE words | |
290 | |
291 3. Repeat steps 1 and 2 with a different count to delete the consecutive | |
292 UPPER CASE words with one command | |
293 | |
294 ---> this ABC DE line FGHI JK LMN OP of words is Q RS TUV cleaned up. | |
295 | |
296 NOTE: A count between the operator d and the motion works similar to | |
297 using the motion without an operator. | |
298 | |
299 | |
300 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
301 Lesson 2.6: OPERATING ON LINES | |
302 | |
303 | |
304 ** Type dd to delete a whole line. ** | |
212 | 305 |
213 Due to the frequency of whole line deletion, the designers of Vi decided | 306 Due to the frequency of whole line deletion, the designers of Vi decided |
214 it would be easier to simply type two d's in a row to delete a line. | 307 it would be easier to simply type two d's to delete a line. |
215 | 308 |
216 1. Move the cursor to the second line in the phrase below. | 309 1. Move the cursor to the second line in the phrase below. |
217 2. Type dd to delete the line. | 310 2. Type dd to delete the line. |
218 3. Now move to the fourth line. | 311 3. Now move to the fourth line. |
219 4. Type 2dd (remember number-command-object) to delete the two lines. | 312 4. Type 2dd to delete two lines. |
220 | 313 |
221 1) Roses are red, | 314 ---> 1) Roses are red, |
222 2) Mud is fun, | 315 ---> 2) Mud is fun, |
223 3) Violets are blue, | 316 ---> 3) Violets are blue, |
224 4) I have a car, | 317 ---> 4) I have a car, |
225 5) Clocks tell time, | 318 ---> 5) Clocks tell time, |
226 6) Sugar is sweet | 319 ---> 6) Sugar is sweet |
227 7) And so are you. | 320 ---> 7) And so are you. |
228 | 321 |
229 | 322 |
230 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 323 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
231 Lesson 2.5: THE UNDO COMMAND | 324 Lesson 2.7: THE UNDO COMMAND |
232 | 325 |
233 | 326 |
234 ** Press u to undo the last commands, U to fix a whole line. ** | 327 ** Press u to undo the last commands, U to fix a whole line. ** |
235 | 328 |
236 1. Move the cursor to the line below marked ---> and place it on the | 329 1. Move the cursor to the line below marked ---> and place it on the |
237 first error. | 330 first error. |
238 2. Type x to delete the first unwanted character. | 331 2. Type x to delete the first unwanted character. |
239 3. Now type u to undo the last command executed. | 332 3. Now type u to undo the last command executed. |
252 | 345 |
253 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 346 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
254 LESSON 2 SUMMARY | 347 LESSON 2 SUMMARY |
255 | 348 |
256 | 349 |
257 1. To delete from the cursor to the end of a word type: dw | 350 1. To delete from the cursor upto the next word type: dw |
258 | |
259 2. To delete from the cursor to the end of a line type: d$ | 351 2. To delete from the cursor to the end of a line type: d$ |
260 | |
261 3. To delete a whole line type: dd | 352 3. To delete a whole line type: dd |
262 | 353 |
263 4. The format for a command in Normal mode is: | 354 4. To repeat a motion prepend it with a number: 2w |
264 | 355 5. The format for a change command is: |
265 [number] command object OR command [number] object | 356 operator [number] motion |
266 where: | 357 where: |
267 number - is how many times to repeat the command | 358 operator - is what to do, such as d for delete |
268 command - is what to do, such as d for delete | 359 [number] - is an optional count to repeat the motion |
269 object - is what the command should act upon, such as w (word), | 360 motion - moves over the text to operator on, such as w (word), |
270 $ (to the end of line), etc. | 361 $ (to the end of line), etc. |
271 | 362 |
272 5. To undo previous actions, type: u (lowercase u) | 363 6. To move to the start of the line use a zero: 0 |
273 To undo all the changes on a line type: U (capital U) | 364 |
274 To undo the undo's type: CTRL-R | 365 7. To undo previous actions, type: u (lowercase u) |
366 To undo all the changes on a line, type: U (capital U) | |
367 To undo the undo's, type: CTRL-R | |
275 | 368 |
276 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 369 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
277 Lesson 3.1: THE PUT COMMAND | 370 Lesson 3.1: THE PUT COMMAND |
278 | 371 |
279 | 372 |
280 ** Type p to put the last deletion after the cursor. ** | 373 ** Type p to put previously deleted text after the cursor. ** |
281 | 374 |
282 1. Move the cursor to the first line in the set below. | 375 1. Move the cursor to the first ---> line below. |
283 | 376 |
284 2. Type dd to delete the line and store it in Vim's buffer. | 377 2. Type dd to delete the line and store it in a Vim register. |
285 | 378 |
286 3. Move the cursor to the line ABOVE where the deleted line should go. | 379 3. Move the cursor to the c) line, ABOVE where the deleted line should go. |
287 | 380 |
288 4. While in Normal mode, type p to replace the line. | 381 4. Type p to put the line below the cursor. |
289 | 382 |
290 5. Repeat steps 2 through 4 to put all the lines in correct order. | 383 5. Repeat steps 2 through 4 to put all the lines in correct order. |
291 | 384 |
292 d) Can you learn too? | 385 ---> d) Can you learn too? |
293 b) Violets are blue, | 386 ---> b) Violets are blue, |
294 c) Intelligence is learned, | 387 ---> c) Intelligence is learned, |
295 a) Roses are red, | 388 ---> a) Roses are red, |
296 | 389 |
297 | 390 |
298 | 391 |
299 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 392 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
300 Lesson 3.2: THE REPLACE COMMAND | 393 Lesson 3.2: THE REPLACE COMMAND |
301 | 394 |
302 | 395 |
303 ** Type r and a character to replace the character under the cursor. ** | 396 ** Type rx to replace the character at the cursor with x . ** |
304 | 397 |
305 1. Move the cursor to the first line below marked --->. | 398 1. Move the cursor to the first line below marked --->. |
306 | 399 |
307 2. Move the cursor so that it is on top of the first error. | 400 2. Move the cursor so that it is on top of the first error. |
308 | 401 |
309 3. Type r and then the character which should replace the error. | 402 3. Type r and then the character which should be there. |
310 | 403 |
311 4. Repeat steps 2 and 3 until the first line is correct. | 404 4. Repeat steps 2 and 3 until the first line is equal to the second one. |
312 | 405 |
313 ---> Whan this lime was tuoed in, someone presswd some wrojg keys! | 406 ---> Whan this lime was tuoed in, someone presswd some wrojg keys! |
314 ---> When this line was typed in, someone pressed some wrong keys! | 407 ---> When this line was typed in, someone pressed some wrong keys! |
315 | 408 |
316 5. Now move on to Lesson 3.2. | 409 5. Now move on to Lesson 3.2. |
317 | 410 |
318 NOTE: Remember that you should be learning by use, not memorization. | 411 NOTE: Remember that you should be learning by doing, not memorization. |
319 | 412 |
320 | 413 |
321 | 414 |
322 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 415 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
323 Lesson 3.3: THE CHANGE COMMAND | 416 Lesson 3.3: THE CHANGE OPERATOR |
324 | 417 |
325 | 418 |
326 ** To change part or all of a word, type cw . ** | 419 ** To change until the end of a word, type ce . ** |
327 | 420 |
328 1. Move the cursor to the first line below marked --->. | 421 1. Move the cursor to the first line below marked --->. |
329 | 422 |
330 2. Place the cursor on the u in lubw. | 423 2. Place the cursor on the u in lubw. |
331 | 424 |
332 3. Type cw and the correct word (in this case, type 'ine'.) | 425 3. Type ce and the correct word (in this case, type ine ). |
333 | 426 |
334 4. Press <ESC> and move to the next error (the first character to be changed.) | 427 4. Press <ESC> and move to the next character that needs to be changed. |
335 | 428 |
336 5. Repeat steps 3 and 4 until the first sentence is the same as the second. | 429 5. Repeat steps 3 and 4 until the first sentence is the same as the second. |
337 | 430 |
338 ---> This lubw has a few wptfd that mrrf changing usf the change command. | 431 ---> This lubw has a few wptfd that mrrf changing usf the change command. |
339 ---> This line has a few words that need changing using the change command. | 432 ---> This line has a few words that need changing using the change command. |
340 | 433 |
341 Notice that cw not only replaces the word, but also places you in insert. | 434 Notice that ce deletes the word and places you in Insert mode. |
342 | 435 |
343 | 436 |
344 | 437 |
345 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 438 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
346 Lesson 3.4: MORE CHANGES USING c | 439 Lesson 3.4: MORE CHANGES USING c |
347 | 440 |
348 | 441 |
349 ** The change command is used with the same objects as delete. ** | 442 ** The change command is used with the same motions as delete. ** |
350 | 443 |
351 1. The change command works in the same way as delete. The format is: | 444 1. The change operator works in the same way as delete. The format is: |
352 | 445 |
353 [number] c object OR c [number] object | 446 c [number] motion |
354 | 447 |
355 2. The objects are also the same, such as w (word), $ (end of line), etc. | 448 2. The motions are the same, such as w (word) and $ (end of line). |
356 | 449 |
357 3. Move to the first line below marked --->. | 450 3. Move to the first line below marked --->. |
358 | 451 |
359 4. Move the cursor to the first error. | 452 4. Move the cursor to the first error. |
360 | 453 |
361 5. Type c$ to make the rest of the line like the second and press <ESC>. | 454 5. Type c$ and type the rest of the line like the second and press <ESC>. |
362 | 455 |
363 ---> The end of this line needs some help to make it like the second. | 456 ---> The end of this line needs some help to make it like the second. |
364 ---> The end of this line needs to be corrected using the c$ command. | 457 ---> The end of this line needs to be corrected using the c$ command. |
365 | 458 |
366 | 459 NOTE: You can use the Backspace key to correct mistakes while typing. |
367 | 460 |
368 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 461 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
369 LESSON 3 SUMMARY | 462 LESSON 3 SUMMARY |
370 | 463 |
371 | 464 |
372 1. To replace text that has already been deleted, type p . This Puts the | 465 1. To put back text that has just been deleted, type p . This puts the |
373 deleted text AFTER the cursor (if a line was deleted it will go on the | 466 deleted text AFTER the cursor (if a line was deleted it will go on the |
374 line below the cursor). | 467 line below the cursor). |
375 | 468 |
376 2. To replace the character under the cursor, type r and then the | 469 2. To replace the character under the cursor, type r and then the |
377 character which will replace the original. | 470 character you want to have there. |
378 | 471 |
379 3. The change command allows you to change the specified object from the | 472 3. The change operator allows you to change from the cursor to where the |
380 cursor to the end of the object. eg. Type cw to change from the | 473 motion takes you. eg. Type ce to change from the cursor to the end of |
381 cursor to the end of the word, c$ to change to the end of a line. | 474 the word, c$ to change to the end of a line. |
382 | 475 |
383 4. The format for change is: | 476 4. The format for change is: |
384 | 477 |
385 [number] c object OR c [number] object | 478 c [number] motion |
386 | 479 |
387 Now go on to the next lesson. | 480 Now go on to the next lesson. |
388 | 481 |
389 | 482 |
390 | 483 |
391 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 484 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
392 Lesson 4.1: LOCATION AND FILE STATUS | 485 Lesson 4.1: CURSOR LOCATION AND FILE STATUS |
393 | 486 |
394 | 487 ** Type CTRL-G to show your location in the file and the file status. |
395 ** 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. ** |
396 Type SHIFT-G to move to a line in the file. ** | |
397 | 489 |
398 Note: Read this entire lesson before executing any of the steps!! | 490 Note: Read this entire lesson before executing any of the steps!! |
399 | 491 |
400 1. Hold down the Ctrl key and press g . A status line will appear at the | 492 1. Hold down the Ctrl key and press g . We call this CTRL-G. |
401 bottom of the page with the filename and the line you are on. Remember | 493 A message will appear at the bottom of the page with the filename and the |
402 the line number for Step 3. | 494 position in the file. Remember the line number for Step 3. |
403 | 495 |
404 2. Press shift-G to move you to the bottom of the file. | 496 NOTE: You may see the cursor position in the lower right corner of the screen |
405 | 497 This happens when the 'ruler' option is set (explained in lesson 6). |
406 3. Type in the number of the line you were on and then shift-G. This will | 498 |
407 return you to the line you were on when you first pressed Ctrl-g. | 499 2. Press G to move you to the bottom of the file. |
408 (When you type in the numbers, they will NOT be displayed on the screen.) | 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. | |
409 | 504 |
410 4. If you feel confident to do this, execute steps 1 through 3. | 505 4. If you feel confident to do this, execute steps 1 through 3. |
411 | |
412 | |
413 | 506 |
414 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 507 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
415 Lesson 4.2: THE SEARCH COMMAND | 508 Lesson 4.2: THE SEARCH COMMAND |
416 | 509 |
417 | 510 |
421 appear at the bottom of the screen as with the : command. | 514 appear at the bottom of the screen as with the : command. |
422 | 515 |
423 2. Now type 'errroor' <ENTER>. This is the word you want to search for. | 516 2. Now type 'errroor' <ENTER>. This is the word you want to search for. |
424 | 517 |
425 3. To search for the same phrase again, simply type n . | 518 3. To search for the same phrase again, simply type n . |
426 To search for the same phrase in the opposite direction, type Shift-N . | 519 To search for the same phrase in the opposite direction, type N . |
427 | 520 |
428 4. If you want to search for a phrase in the backwards direction, use the | 521 4. To search for a phrase in the backward direction, use ? instead of / . |
429 command ? instead of /. | 522 |
430 | 523 5. To go back to where you came from press CTRL-O (Keep Ctrl down while |
431 ---> "errroor" is not the way to spell error; errroor is an error. | 524 pressing the letter o). Repeat to go back further. CTRL-I goes forward. |
432 | 525 |
526 Note: "errroor" is not the way to spell error; errroor is an error. | |
433 Note: When the search reaches the end of the file it will continue at the | 527 Note: When the search reaches the end of the file it will continue at the |
434 start. | 528 start, unless the 'wrapscan' option has been reset. |
435 | |
436 | 529 |
437 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 530 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
438 Lesson 4.3: MATCHING PARENTHESES SEARCH | 531 Lesson 4.3: MATCHING PARENTHESES SEARCH |
439 | 532 |
440 | 533 |
442 | 535 |
443 1. Place the cursor on any (, [, or { in the line below marked --->. | 536 1. Place the cursor on any (, [, or { in the line below marked --->. |
444 | 537 |
445 2. Now type the % character. | 538 2. Now type the % character. |
446 | 539 |
447 3. The cursor should be on the matching parenthesis or bracket. | 540 3. The cursor will move to the matching parenthesis or bracket. |
448 | 541 |
449 4. Type % to move the cursor back to the first bracket (by matching). | 542 4. Type % to move the cursor to the other matching bracket. |
543 | |
544 5. Move the cursor to another (,),[,],{ or } and see what % does. | |
450 | 545 |
451 ---> This ( is a test line with ('s, ['s ] and {'s } in it. )) | 546 ---> This ( is a test line with ('s, ['s ] and {'s } in it. )) |
452 | 547 |
548 | |
453 Note: This is very useful in debugging a program with unmatched parentheses! | 549 Note: This is very useful in debugging a program with unmatched parentheses! |
454 | 550 |
455 | 551 |
456 | 552 |
457 | 553 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
458 | 554 Lesson 4.4: THE SUBSTITUTE COMMAND |
459 | |
460 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
461 Lesson 4.4: A WAY TO CHANGE ERRORS | |
462 | 555 |
463 | 556 |
464 ** Type :s/old/new/g to substitute 'new' for 'old'. ** | 557 ** Type :s/old/new/g to substitute 'new' for 'old'. ** |
465 | 558 |
466 1. Move the cursor to the line below marked --->. | 559 1. Move the cursor to the line below marked --->. |
467 | 560 |
468 2. Type :s/thee/the <ENTER> . Note that this command only changes the | 561 2. Type :s/thee/the <ENTER> . Note that this command only changes the |
469 first occurrence on the line. | 562 first occurrence of "thee" in the line. |
470 | 563 |
471 3. Now type :s/thee/the/g meaning substitute globally on the line. | 564 3. Now type :s/thee/the/g . Adding the g flag means to substitute |
472 This changes all occurrences on the line. | 565 globally in the line, change all occurrences of "thee" in the line. |
473 | 566 |
474 ---> thee best time to see thee flowers is in thee spring. | 567 ---> thee best time to see thee flowers is in thee spring. |
475 | 568 |
476 4. To change every occurrence of a character string between two lines, | 569 4. To change every occurrence of a character string between two lines, |
477 type :#,#s/old/new/g where #,# are the numbers of the two lines. | 570 type :#,#s/old/new/g where #,# are the line numbers of the range |
478 Type :%s/old/new/g to change every occurrence in the whole file. | 571 of lines where the subsitution is to be done. |
479 | 572 Type :%s/old/new/g to change every occurrence in the whole file. |
480 | 573 Type :%s/old/new/gc to find every occurrence in the whole file, |
481 | 574 with a prompt wether to substitute or not. |
482 | 575 |
483 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 576 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
484 LESSON 4 SUMMARY | 577 LESSON 4 SUMMARY |
485 | 578 |
486 | 579 |
487 1. Ctrl-g displays your location in the file and the file status. | 580 1. CTRL-G displays your location in the file and the file status. |
488 Shift-G moves to the end of the file. A line number followed | 581 G moves to the end of the file. |
489 by Shift-G moves to that line number. | 582 number G moves to that line number. |
583 gg moves to the first line. | |
490 | 584 |
491 2. Typing / followed by a phrase searches FORWARD for the phrase. | 585 2. Typing / followed by a phrase searches FORWARD for the phrase. |
492 Typing ? followed by a phrase searches BACKWARD for the phrase. | 586 Typing ? followed by a phrase searches BACKWARD for the phrase. |
493 After a search type n to find the next occurrence in the same direction | 587 After a search type n to find the next occurrence in the same direction |
494 or Shift-N to search in the opposite direction. | 588 or N to search in the opposite direction. |
495 | 589 CTRL-O takes you back to older positions, CTRL-I to newer positions. |
496 3. Typing % while the cursor is on a (,),[,],{, or } locates its | 590 |
497 matching pair. | 591 3. Typing % while the cursor is on a (,),[,],{, or } goes to its match. |
498 | 592 |
499 4. To substitute new for the first old on a line type :s/old/new | 593 4. To substitute new for the first old in a line type :s/old/new |
500 To substitute new for all 'old's on a line type :s/old/new/g | 594 To substitute new for all 'old's on a line type :s/old/new/g |
501 To substitute phrases between two line #'s type :#,#s/old/new/g | 595 To substitute phrases between two line #'s type :#,#s/old/new/g |
502 To substitute all occurrences in the file type :%s/old/new/g | 596 To substitute all occurrences in the file type :%s/old/new/g |
503 To ask for confirmation each time add 'c' :%s/old/new/gc | 597 To ask for confirmation each time add 'c' :%s/old/new/gc |
504 | 598 |
505 | |
506 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 599 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
507 Lesson 5.1: HOW TO EXECUTE AN EXTERNAL COMMAND | 600 Lesson 5.1: HOW TO EXECUTE AN EXTERNAL COMMAND |
508 | 601 |
509 | 602 |
510 ** Type :! followed by an external command to execute that command. ** | 603 ** Type :! followed by an external command to execute that command. ** |
511 | 604 |
512 1. Type the familiar command : to set the cursor at the bottom of the | 605 1. Type the familiar command : to set the cursor at the bottom of the |
513 screen. This allows you to enter a command. | 606 screen. This allows you to enter a command-line command. |
514 | 607 |
515 2. Now type the ! (exclamation point) character. This allows you to | 608 2. Now type the ! (exclamation point) character. This allows you to |
516 execute any external shell command. | 609 execute any external shell command. |
517 | 610 |
518 3. As an example type ls following the ! and then hit <ENTER>. This | 611 3. As an example type ls following the ! and then hit <ENTER>. This |
519 will show you a listing of your directory, just as if you were at the | 612 will show you a listing of your directory, just as if you were at the |
520 shell prompt. Or use :!dir if ls doesn't work. | 613 shell prompt. Or use :!dir if ls doesn't work. |
521 | 614 |
522 Note: It is possible to execute any external command this way. | 615 Note: It is possible to execute any external command this way, also with |
616 arguments. | |
523 | 617 |
524 Note: All : commands must be finished by hitting <ENTER> | 618 Note: All : commands must be finished by hitting <ENTER> |
525 | 619 From here one we will not always mention it. |
526 | |
527 | 620 |
528 | 621 |
529 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 622 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
530 Lesson 5.2: MORE ON WRITING FILES | 623 Lesson 5.2: MORE ON WRITING FILES |
531 | 624 |
532 | 625 |
533 ** To save the changes made to the file, type :w FILENAME. ** | 626 ** To save the changes made to the text, type :w FILENAME. ** |
534 | 627 |
535 1. Type :!dir or :!ls to get a listing of your directory. | 628 1. Type :!dir or :!ls to get a listing of your directory. |
536 You already know you must hit <ENTER> after this. | 629 You already know you must hit <ENTER> after this. |
537 | 630 |
538 2. Choose a filename that does not exist yet, such as TEST. | 631 2. Choose a filename that does not exist yet, such as TEST. |
539 | 632 |
540 3. Now type: :w TEST (where TEST is the filename you chose.) | 633 3. Now type: :w TEST (where TEST is the filename you chose.) |
541 | 634 |
542 4. This saves the whole file (Vim Tutor) under the name TEST. | 635 4. This saves the whole file (the Vim Tutor) under the name TEST. |
543 To verify this, type :!dir again to see your directory | 636 To verify this, type :!dir or :!ls again to see your directory. |
544 | 637 |
545 Note: If you were to exit Vim and enter again with the filename TEST, the file | 638 Note: If you were to exit Vim and start it again with vim TEST , the file |
546 would be an exact copy of the tutor when you saved it. | 639 would be an exact copy of the tutor when you saved it. |
547 | 640 |
548 5. Now remove the file by typing (MS-DOS): :!del TEST | 641 5. Now remove the file by typing (MS-DOS): :!del TEST |
549 or (Unix): :!rm TEST | 642 or (Unix): :!rm TEST |
550 | 643 |
551 | 644 |
552 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 645 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
553 Lesson 5.3: A SELECTIVE WRITE COMMAND | 646 Lesson 5.3: SELECTING TEXT TO WRITE |
554 | 647 |
555 | 648 |
556 ** To save part of the file, type :#,# w FILENAME ** | 649 ** To save part of the file, type v motion :w FILENAME ** |
557 | 650 |
558 1. Once again, type :!dir or :!ls to obtain a listing of your directory | 651 1. Move the cursor to this line. |
559 and choose a suitable filename such as TEST. | 652 |
560 | 653 2. Press v and move the cursor to the fifth item below. Notice that the |
561 2. Move the cursor to the top of this page and type Ctrl-g to find the | 654 text is highlighted. |
562 number of that line. REMEMBER THIS NUMBER! | 655 |
563 | 656 3. Press the : character. At the bottom of the screen :'<,'> will appear. |
564 3. Now move to the bottom of the page and type Ctrl-g again. REMEMBER THIS | 657 |
565 LINE NUMBER ALSO! | 658 4. Type w TEST , where TEST is a filename that does not exist yet. Verify |
566 | 659 that you see :'<,'>w TEST before you press Enter. |
567 4. To save ONLY a section to a file, type :#,# w TEST where #,# are | 660 |
568 the two numbers you remembered (top,bottom) and TEST is your filename. | 661 5. Vim will write the selected lines to the file TEST. Use :!dir or !ls |
569 | 662 to see it. Do not remove it yet! We will use it in the next lesson. |
570 5. Again, see that the file is there with :!dir but DO NOT remove it. | 663 |
571 | 664 NOTE: Pressing v starts Visual selection. You can move the cursor around |
572 | 665 to make the selection bigger or smaller. Then you can use an operator |
573 | 666 to do something with the text. For example, d deletes the text. |
574 | 667 |
575 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 668 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
576 Lesson 5.4: RETRIEVING AND MERGING FILES | 669 Lesson 5.4: RETRIEVING AND MERGING FILES |
577 | 670 |
578 | 671 |
579 ** To insert the contents of a file, type :r FILENAME ** | 672 ** To insert the contents of a file, type :r FILENAME ** |
580 | 673 |
581 1. Type :!dir to make sure your TEST filename is present from before. | 674 1. Place the cursor just above this line. |
582 | 675 |
583 2. Place the cursor at the top of this page. | 676 NOTE: After executing Step 2 you will see text from Lesson 5.3. Then move |
584 | 677 DOWN to see this lesson again. |
585 NOTE: After executing Step 3 you will see Lesson 5.3. Then move DOWN to | 678 |
586 this lesson again. | 679 2. Now retrieve your TEST file using the command :r TEST where TEST is |
587 | 680 the name of the file you used. |
588 3. Now retrieve your TEST file using the command :r TEST where TEST is | 681 The file you retrieve is placed below the cursor line. |
589 the name of the file. | 682 |
590 | 683 3. To verify that a file was retrieved, cursor back and notice that there |
591 NOTE: The file you retrieve is placed starting where the cursor is located. | |
592 | |
593 4. To verify that a file was retrieved, cursor back and notice that there | |
594 are now two copies of Lesson 5.3, the original and the file version. | 684 are now two copies of Lesson 5.3, the original and the file version. |
595 | 685 |
686 NOTE: 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. | |
596 | 689 |
597 | 690 |
598 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 691 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
599 LESSON 5 SUMMARY | 692 LESSON 5 SUMMARY |
600 | 693 |
606 :!dir :!ls - shows a directory listing. | 699 :!dir :!ls - shows a directory listing. |
607 :!del FILENAME :!rm FILENAME - removes file FILENAME. | 700 :!del FILENAME :!rm FILENAME - removes file FILENAME. |
608 | 701 |
609 2. :w FILENAME writes the current Vim file to disk with name FILENAME. | 702 2. :w FILENAME writes the current Vim file to disk with name FILENAME. |
610 | 703 |
611 3. :#,#w FILENAME saves the lines # through # in file FILENAME. | 704 3. v motion :w FILENAME saves the Visually selected lines in file |
612 | 705 FILENAME. |
613 4. :r FILENAME retrieves disk file FILENAME and inserts it into the | 706 |
614 current file following the cursor position. | 707 4. :r FILENAME retrieves disk file FILENAME and puts it below the |
615 | 708 cursor position. |
616 | 709 |
617 | 710 5. :r !dir reads the output of the dir command and puts it below the |
618 | 711 cursor position |
619 | 712 |
620 | 713 |
621 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 714 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
622 Lesson 6.1: THE OPEN COMMAND | 715 Lesson 6.1: THE OPEN COMMAND |
623 | 716 |
624 | 717 |
625 ** Type o to open a line below the cursor and place you in Insert mode. ** | 718 ** Type o to open a line below the cursor and place you in Insert mode. ** |
626 | 719 |
627 1. Move the cursor to the line below marked --->. | 720 1. Move the cursor to the line below marked --->. |
628 | 721 |
629 2. Type o (lowercase) to open up a line BELOW the cursor and place you in | 722 2. Type the lowercase letter o to open up a line BELOW the cursor and place |
630 Insert mode. | 723 you in Insert mode. |
631 | 724 |
632 3. Now copy the line marked ---> and press <ESC> to exit Insert mode. | 725 3. Now type some text and press <ESC> to exit Insert mode. |
633 | 726 |
634 ---> After typing o the cursor is placed on the open line in Insert mode. | 727 ---> After typing o the cursor is placed on the open line in Insert mode. |
635 | 728 |
636 4. To open up a line ABOVE the cursor, simply type a capital O , rather | 729 4. To open up a line ABOVE the cursor, simply type a capital O , rather |
637 than a lowercase o. Try this on the line below. | 730 than a lowercase o. Try this on the line below. |
638 Open up a line above this by typing Shift-O while the cursor is on this line. | 731 |
639 | 732 ---> Open up a line above this by typing O while the cursor is on this line. |
640 | 733 |
641 | 734 |
642 | 735 |
643 | 736 |
644 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 737 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
645 Lesson 6.2: THE APPEND COMMAND | 738 Lesson 6.2: THE APPEND COMMAND |
646 | 739 |
647 | 740 |
648 ** Type a to insert text AFTER the cursor. ** | 741 ** Type a to insert text AFTER the cursor. ** |
649 | 742 |
650 1. Move the cursor to the end of the first line below marked ---> by | 743 1. Move the cursor to the start of the line below marked --->. |
651 typing $ in Normal mode. | 744 |
652 | 745 2. Press e until the cursor is on the end of li . |
653 2. Type an a (lowercase) to append text AFTER the character under the | 746 |
654 cursor. (Uppercase A appends to the end of the line.) | 747 3. Type an a (lowercase) to append text AFTER the cursor. |
655 | 748 |
656 Note: This avoids typing i , the last character, the text to insert, <ESC>, | 749 4. Complete the word like the line below it. Press <ESC> to exit Insert |
657 cursor-right, and finally, x , just to append to the end of a line! | 750 mode. |
658 | 751 |
659 3. Now complete the first line. Note also that append is exactly the same | 752 5. Use e to move to the next incomplete word and repeat steps 3 and 4. |
660 as Insert mode, except for the location where text is inserted. | 753 |
661 | 754 ---> This li will allow you to pract appendi text to a line. |
662 ---> This line will allow you to practice | 755 ---> This line will allow you to practice appending text to a line. |
663 ---> This line will allow you to practice appending text to the end of a line. | 756 |
664 | 757 Note: a, i and A all go to the same Insert mode, the only difference is where |
665 | 758 the characters are inserted. |
666 | 759 |
667 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 760 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
668 Lesson 6.3: ANOTHER VERSION OF REPLACE | 761 Lesson 6.3: ANOTHER WAY TO REPLACE |
669 | 762 |
670 | 763 |
671 ** Type a capital R to replace more than one character. ** | 764 ** Type a capital R to replace more than one character. ** |
672 | 765 |
673 1. Move the cursor to the first line below marked --->. | 766 1. Move the cursor to the first line below marked --->. Move the cursor to |
674 | 767 the beginning of the first xxx . |
675 2. Place the cursor at the beginning of the first word that is different | 768 |
676 from the second line marked ---> (the word 'last'). | 769 2. Now press R and type the number below it in the second line, so that it |
677 | 770 replaces the xxx . |
678 3. Now type R and replace the remainder of the text on the first line by | 771 |
679 typing over the old text to make the first line the same as the second. | 772 3. Press <ESC> to leave Replace mode. Notice that the rest of the line |
680 | 773 remains unmodified. |
681 ---> To make the first line the same as the last on this page use the keys. | 774 |
682 ---> To make the first line the same as the second, type R and the new text. | 775 5. Repeat the steps to replace the remaining xxx. |
683 | 776 |
684 4. Note that when you press <ESC> to exit, any unaltered text remains. | 777 ---> Adding 123 to xxx gives you xxx. |
685 | 778 ---> Adding 123 to 456 gives you 579. |
686 | 779 |
687 | 780 NOTE: Replace mode is like Insert mode, but every typed character deletes an |
688 | 781 existing character. |
689 | 782 |
690 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 783 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
691 Lesson 6.4: SET OPTION | 784 Lesson 6.4: COPY AND PASTE TEXT |
785 | |
786 | |
787 ** use the y operator to copy text and p to paste it ** | |
788 | |
789 1. Go to the line marked with ---> below and place the cursor after "a)". | |
790 | |
791 2. Start Visual mode with v and move the cursor to just before "first". | |
792 | |
793 3. Type y to yank (copy) the highlighted text. | |
794 | |
795 4. Move the cursor to the end of the next line: j$ | |
796 | |
797 5. Type p to put (paste) the text. Then type: a second <ESC> . | |
798 | |
799 6. Use Visual mode to select " item.", yank it with y , move to the end of | |
800 the next line with j$ and put the text there with p . | |
801 | |
802 ---> a) this is the first item. | |
803 b) | |
804 | |
805 Note: you can also use y as an operator; yw yanks one word. | |
806 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
807 Lesson 6.5: SET OPTION | |
808 | |
692 | 809 |
693 ** Set an option so a search or substitute ignores case ** | 810 ** Set an option so a search or substitute ignores case ** |
694 | 811 |
695 1. Search for 'ignore' by entering: | 812 1. Search for 'ignore' by entering: /ignore <ENTER> |
696 /ignore | 813 Repeat several times by pressing n . |
697 Repeat several times by hitting the n key | 814 |
698 | 815 2. Set the 'ic' (Ignore case) option by entering: :set ic |
699 2. Set the 'ic' (Ignore case) option by typing: | 816 |
700 :set ic | 817 3. Now search for 'ignore' again by pressing n |
701 | 818 Notice that Ignore and IGNORE are now also found. |
702 3. Now search for 'ignore' again by entering: n | 819 |
703 Repeat search several more times by hitting the n key | 820 4. Set the 'hlsearch' and 'incsearch' options: :set hls is |
704 | 821 |
705 4. Set the 'hlsearch' and 'incsearch' options: | 822 5. Now type the search command again and see what happens: /ignore <ENTER> |
706 :set hls is | 823 |
707 | 824 6. To disable ignoring case enter: :set noic |
708 5. Now enter the search command again, and see what happens: | 825 |
709 /ignore | 826 Note: To remove the highlighting of matches enter: :nohlsearch |
710 | 827 Note: If you want to ignore case for just one search command, use \c |
711 6. To remove the highlighting of matches, type: | 828 in the phrase: /ignore\c <ENTER> |
712 :nohlsearch | |
713 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 829 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
714 LESSON 6 SUMMARY | 830 LESSON 6 SUMMARY |
715 | 831 |
716 | 832 1. Type o to open a line BELOW the cursor and start Insert mode. |
717 1. Typing o opens a line BELOW the cursor and places the cursor on the open | 833 Type O to open a line ABOVE the cursor. |
718 line in Insert mode. | 834 |
719 Typing a capital O opens the line ABOVE the line the cursor is on. | 835 2. Type a to insert text AFTER the cursor. |
720 | 836 Type A to insert text after the end of the line. |
721 2. Type an a to insert text AFTER the character the cursor is on. | 837 |
722 Typing a capital A automatically appends text to the end of the line. | 838 3. The e command moves to the end of a word. |
723 | 839 |
724 3. Typing a capital R enters Replace mode until <ESC> is pressed to exit. | 840 4. The y operator yanks (copies) text, p puts (pastes) it. |
725 | 841 |
726 4. Typing ":set xxx" sets the option "xxx" | 842 5. Typing a capital R enters Replace mode until <ESC> is pressed. |
727 | 843 |
728 | 844 6. Typing ":set xxx" sets the option "xxx". Some options are: |
729 | 845 'ic' 'ignorecase' ignore upper/lower case when searching |
730 | 846 'is' 'incsearch' show partial matches for a search phrase |
731 | 847 'hls' 'hlsearch' highlight all matching phrases |
732 | 848 You can either use the long or the short option name. |
733 | 849 |
734 | 850 7. Prepend "no" to switch an option off: :set noic |
735 | 851 |
736 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 852 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
737 LESSON 7: ON-LINE HELP COMMANDS | 853 LESSON 7.1: GETTING HELP |
738 | 854 |
739 | 855 |
740 ** Use the on-line help system ** | 856 ** Use the on-line help system ** |
741 | 857 |
742 Vim has a comprehensive on-line help system. To get started, try one of | 858 Vim has a comprehensive on-line help system. To get started, try one of |
743 these three: | 859 these three: |
744 - press the <HELP> key (if you have one) | 860 - press the <HELP> key (if you have one) |
745 - press the <F1> key (if you have one) | 861 - press the <F1> key (if you have one) |
746 - type :help <ENTER> | 862 - type :help <ENTER> |
747 | 863 |
748 Type :q <ENTER> to close the help window. | 864 Read the text in the help window to find out how the help works. |
865 type CTRL-W CTRL-W to jump from one window to another | |
866 Type :q <ENTER> to close the help window. | |
749 | 867 |
750 You can find help on just about any subject, by giving an argument to the | 868 You can find help on just about any subject, by giving an argument to the |
751 ":help" command. Try these (don't forget pressing <ENTER>): | 869 ":help" command. Try these (don't forget pressing <ENTER>): |
752 | 870 |
753 :help w | 871 :help w |
754 :help c_<T | 872 :help c_CTRL-D |
755 :help insert-index | 873 :help insert-index |
756 :help user-manual | 874 :help user-manual |
757 | 875 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
758 | 876 LESSON 7.2: CREATE A STARTUP SCRIPT |
759 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 877 |
760 LESSON 8: CREATE A STARTUP SCRIPT | 878 |
761 | 879 ** Enable Vim features ** |
762 ** Switch on Vim features ** | 880 |
763 | 881 Vim has many more features than Vi, but most of them are disabled by |
764 Vim has many more features than Vi, but most of them are disabled by default. | 882 default. To start using more features you have to create a "vimrc" file. |
765 To start using more features you have to create a "vimrc" file. | 883 |
766 | 884 1. Start editing the "vimrc" file. This depends on your system: |
767 1. Start editing the "vimrc" file, this depends on your system: | 885 :e ~/.vimrc for Unix |
768 :edit ~/.vimrc for Unix | 886 :e $VIM/_vimrc for MS-Windows |
769 :edit $VIM/_vimrc for MS-Windows | 887 |
770 | 888 2. Now read the example "vimrc" file contents: |
771 2. Now read the example "vimrc" file text: | 889 :r $VIMRUNTIME/vimrc_example.vim |
772 | |
773 :read $VIMRUNTIME/vimrc_example.vim | |
774 | 890 |
775 3. Write the file with: | 891 3. Write the file with: |
776 | 892 :w |
777 :write | |
778 | 893 |
779 The next time you start Vim it will use syntax highlighting. | 894 The next time you start Vim it will use syntax highlighting. |
780 You can add all your preferred settings to this "vimrc" file. | 895 You can add all your preferred settings to this "vimrc" file. |
896 For more information type :help vimrc-intro | |
897 | |
898 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
899 LESSON 7.3: COMPLETION | |
900 | |
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 | |
912 5. Press <TAB> and Vim will complete the command name to ":edit". | |
913 | |
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 | |
918 NOTE: Completion works for many commands. Just try pressing CTRL-D and | |
919 <TAB>. It is especially useful for :help . | |
920 | |
921 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
922 LESSON 7 SUMMARY | |
923 | |
924 | |
925 1. Type :help or press <F1> or <Help> to open a help window. | |
926 | |
927 2. Type :help cmd to find help on cmd . | |
928 | |
929 3. Type CTRL-W CTRL-W to jump to another window | |
930 | |
931 4. Type :q to close the help window | |
932 | |
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 | |
781 | 943 |
782 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 944 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
783 | 945 |
784 This concludes the Vim Tutor. It was intended to give a brief overview of | 946 This concludes the Vim Tutor. It was intended to give a brief overview of |
785 the Vim editor, just enough to allow you to use the editor fairly easily. | 947 the Vim editor, just enough to allow you to use the editor fairly easily. |