comparison runtime/tutor/tutor @ 7:3fc0f57ecb91 v7.0001

updated for version 7.0001
author vimboss
date Sun, 13 Jun 2004 20:20:40 +0000
parents
children 4424b47a0797
comparison
equal deleted inserted replaced
6:c2daee826b8f 7:3fc0f57ecb91
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 =
3 ===============================================================================
4
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
7 enough of the commands that you will be able to easily use Vim as
8 an all-purpose editor.
9
10 The approximate time required to complete the tutor is 25-30 minutes,
11 depending upon how much time is spent with experimentation.
12
13 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
16 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 properly. If you only read the text, you will forget the commands!
19
20 Now, make sure that your Shift-Lock key is NOT depressed and press
21 the j key enough times to move the cursor so that Lesson 1.1
22 completely fills the screen.
23 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 Lesson 1.1: MOVING THE CURSOR
25
26
27 ** To move the cursor, press the h,j,k,l keys as indicated. **
28 ^
29 k Hint: The h key is at the left and moves left.
30 < h l > The l key is at the right and moves right.
31 j The j key looks like a down arrow
32 v
33 1. Move the cursor around the screen until you are comfortable.
34
35 2. Hold down the down key (j) until it repeats.
36 ---> Now you know how to move to the next lesson.
37
38 3. Using the down key, move to Lesson 1.2.
39
40 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
43 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
46 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47 Lesson 1.2: ENTERING AND EXITING VIM
48
49
50 !! NOTE: Before executing any of the steps below, read this entire lesson!!
51
52 1. Press the <ESC> key (to make sure you are in Normal mode).
53
54 2. Type: :q! <ENTER>.
55
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
60 3. When you see the shell prompt, type the command that got you into this
61 tutor. That could 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
66 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
68 to Lesson 1.3.
69 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70 Lesson 1.3: TEXT EDITING - DELETION
71
72
73 ** While in Normal mode press x to delete the character under the cursor. **
74
75 1. Move the cursor to the line below marked --->.
76
77 2. To fix the errors, move the cursor until it is on top of the
78 character to be deleted.
79
80 3. Press the x key to delete the unwanted character.
81
82 4. Repeat steps 2 through 4 until the sentence is correct.
83
84 ---> The ccow jumpedd ovverr thhe mooon.
85
86 5. Now that the line is correct, go on to Lesson 1.4.
87
88 NOTE: As you go through this tutor, do not try to memorize, learn by usage.
89
90
91
92 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93 Lesson 1.4: TEXT EDITING - INSERTION
94
95
96 ** While in Normal mode press i to insert text. **
97
98 1. Move the cursor to the first line below marked --->.
99
100 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
103 3. Press i and type in the necessary additions.
104
105 4. As each error is fixed press <ESC> to return to Normal mode.
106 Repeat steps 2 through 4 to correct the sentence.
107
108 ---> There is text misng this .
109 ---> There is some text missing from this line.
110
111 5. When you are comfortable inserting text move to the summary below.
112
113
114
115 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116 LESSON 1 SUMMARY
117
118
119 1. The cursor is moved using either the arrow keys or the hjkl keys.
120 h (left) j (down) k (up) l (right)
121
122 2. To enter Vim (from the % prompt) type: vim FILENAME <ENTER>
123
124 3. To exit Vim type: <ESC> :q! <ENTER> to trash all changes.
125 OR type: <ESC> :wq <ENTER> to save the changes.
126
127 4. To delete a character under the cursor in Normal mode type: x
128
129 5. To insert text at the cursor while in Normal mode type:
130 i type in text <ESC>
131
132 NOTE: Pressing <ESC> will place you in Normal mode or will cancel
133 an unwanted and partially completed command.
134
135 Now continue with Lesson 2.
136
137
138 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139 Lesson 2.1: DELETION COMMANDS
140
141
142 ** Type dw to delete to the end of a word. **
143
144 1. Press <ESC> to make sure you are in Normal mode.
145
146 2. Move the cursor to the line below marked --->.
147
148 3. Move the cursor to the beginning of a word that needs to be deleted.
149
150 4. Type dw to make the word disappear.
151
152 NOTE: The letters dw will appear on the last line of the screen as you type
153 them. If you typed something wrong, press <ESC> and start over.
154
155 ---> There are a some words fun that don't belong paper in this sentence.
156
157 5. Repeat steps 3 and 4 until the sentence is correct and go to Lesson 2.2.
158
159
160
161 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162 Lesson 2.2: MORE DELETION COMMANDS
163
164
165 ** Type d$ to delete to the end of the line. **
166
167 1. Press <ESC> to make sure you are in Normal mode.
168
169 2. Move the cursor to the line below marked --->.
170
171 3. Move the cursor to the end of the correct line (AFTER the first . ).
172
173 4. Type d$ to delete to the end of the line.
174
175 ---> Somebody typed the end of this line twice. end of this line twice.
176
177
178 5. Move on to Lesson 2.3 to understand what is happening.
179
180
181
182
183
184 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185 Lesson 2.3: ON COMMANDS AND OBJECTS
186
187
188 The format for the d delete command is as follows:
189
190 [number] d object OR d [number] object
191 Where:
192 number - is how many times to execute the command (optional, default=1).
193 d - is the command to delete.
194 object - is what the command will operate on (listed below).
195
196 A short list of objects:
197 w - from the cursor to the end of the word, including the space.
198 e - from the cursor to the end of the word, NOT including the space.
199 $ - from the cursor to the end of the line.
200
201 NOTE: For the adventurous, pressing just the object while in Normal mode
202 without a command will move the cursor as specified in the object list.
203
204
205
206
207 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208 Lesson 2.4: AN EXCEPTION TO 'COMMAND-OBJECT'
209
210
211 ** Type dd to delete a whole line. **
212
213 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.
215
216 1. Move the cursor to the second line in the phrase below.
217 2. Type dd to delete the line.
218 3. Now move to the fourth line.
219 4. Type 2dd (remember number-command-object) to delete the two lines.
220
221 1) Roses are red,
222 2) Mud is fun,
223 3) Violets are blue,
224 4) I have a car,
225 5) Clocks tell time,
226 6) Sugar is sweet
227 7) And so are you.
228
229
230 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231 Lesson 2.5: THE UNDO COMMAND
232
233
234 ** Press u to undo the last commands, U to fix a whole line. **
235
236 1. Move the cursor to the line below marked ---> and place it on the
237 first error.
238 2. Type x to delete the first unwanted character.
239 3. Now type u to undo the last command executed.
240 4. This time fix all the errors on the line using the x command.
241 5. Now type a capital U to return the line to its original state.
242 6. Now type u a few times to undo the U and preceding commands.
243 7. Now type CTRL-R (keeping CTRL key pressed while hitting R) a few times
244 to redo the commands (undo the undo's).
245
246 ---> Fiix the errors oon thhis line and reeplace them witth undo.
247
248 8. These are very useful commands. Now move on to the Lesson 2 Summary.
249
250
251
252
253 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
254 LESSON 2 SUMMARY
255
256
257 1. To delete from the cursor to the end of a word type: dw
258
259 2. To delete from the cursor to the end of a line type: d$
260
261 3. To delete a whole line type: dd
262
263 4. The format for a command in Normal mode is:
264
265 [number] command object OR command [number] object
266 where:
267 number - is how many times to repeat the command
268 command - is what to do, such as d for delete
269 object - is what the command should act upon, such as w (word),
270 $ (to the end of line), etc.
271
272 5. To undo previous actions, type: u (lowercase u)
273 To undo all the changes on a line type: U (capital U)
274 To undo the undo's type: CTRL-R
275
276 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
277 Lesson 3.1: THE PUT COMMAND
278
279
280 ** Type p to put the last deletion after the cursor. **
281
282 1. Move the cursor to the first line in the set below.
283
284 2. Type dd to delete the line and store it in Vim's buffer.
285
286 3. Move the cursor to the line ABOVE where the deleted line should go.
287
288 4. While in Normal mode, type p to replace the line.
289
290 5. Repeat steps 2 through 4 to put all the lines in correct order.
291
292 d) Can you learn too?
293 b) Violets are blue,
294 c) Intelligence is learned,
295 a) Roses are red,
296
297
298
299 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
300 Lesson 3.2: THE REPLACE COMMAND
301
302
303 ** Type r and a character to replace the character under the cursor. **
304
305 1. Move the cursor to the first line below marked --->.
306
307 2. Move the cursor so that it is on top of the first error.
308
309 3. Type r and then the character which should replace the error.
310
311 4. Repeat steps 2 and 3 until the first line is correct.
312
313 ---> Whan this lime was tuoed in, someone presswd some wrojg keys!
314 ---> When this line was typed in, someone pressed some wrong keys!
315
316 5. Now move on to Lesson 3.2.
317
318 NOTE: Remember that you should be learning by use, not memorization.
319
320
321
322 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
323 Lesson 3.3: THE CHANGE COMMAND
324
325
326 ** To change part or all of a word, type cw . **
327
328 1. Move the cursor to the first line below marked --->.
329
330 2. Place the cursor on the u in lubw.
331
332 3. Type cw and the correct word (in this case, type 'ine'.)
333
334 4. Press <ESC> and move to the next error (the first character to be changed.)
335
336 5. Repeat steps 3 and 4 until the first sentence is the same as the second.
337
338 ---> 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.
340
341 Notice that cw not only replaces the word, but also places you in insert.
342
343
344
345 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
346 Lesson 3.4: MORE CHANGES USING c
347
348
349 ** The change command is used with the same objects as delete. **
350
351 1. The change command works in the same way as delete. The format is:
352
353 [number] c object OR c [number] object
354
355 2. The objects are also the same, such as w (word), $ (end of line), etc.
356
357 3. Move to the first line below marked --->.
358
359 4. Move the cursor to the first error.
360
361 5. Type c$ to make the rest of the line like the second and press <ESC>.
362
363 ---> 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.
365
366
367
368 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
369 LESSON 3 SUMMARY
370
371
372 1. To replace text that has already been deleted, type p . This Puts the
373 deleted text AFTER the cursor (if a line was deleted it will go on the
374 line below the cursor).
375
376 2. To replace the character under the cursor, type r and then the
377 character which will replace the original.
378
379 3. The change command allows you to change the specified object from the
380 cursor to the end of the object. eg. Type cw to change from the
381 cursor to the end of the word, c$ to change to the end of a line.
382
383 4. The format for change is:
384
385 [number] c object OR c [number] object
386
387 Now go on to the next lesson.
388
389
390
391 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
392 Lesson 4.1: LOCATION AND FILE STATUS
393
394
395 ** Type CTRL-g to show your location in the file and the file status.
396 Type SHIFT-G to move to a line in the file. **
397
398 Note: Read this entire lesson before executing any of the steps!!
399
400 1. Hold down the Ctrl key and press g . A status line will appear at the
401 bottom of the page with the filename and the line you are on. Remember
402 the line number for Step 3.
403
404 2. Press shift-G to move you to the bottom of the file.
405
406 3. Type in the number of the line you were on and then shift-G. This will
407 return you to the line you were on when you first pressed Ctrl-g.
408 (When you type in the numbers, they will NOT be displayed on the screen.)
409
410 4. If you feel confident to do this, execute steps 1 through 3.
411
412
413
414 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
415 Lesson 4.2: THE SEARCH COMMAND
416
417
418 ** Type / followed by a phrase to search for the phrase. **
419
420 1. In Normal mode type the / character. Notice that it and the cursor
421 appear at the bottom of the screen as with the : command.
422
423 2. Now type 'errroor' <ENTER>. This is the word you want to search for.
424
425 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 .
427
428 4. If you want to search for a phrase in the backwards direction, use the
429 command ? instead of /.
430
431 ---> "errroor" is not the way to spell error; errroor is an error.
432
433 Note: When the search reaches the end of the file it will continue at the
434 start.
435
436
437 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
438 Lesson 4.3: MATCHING PARENTHESES SEARCH
439
440
441 ** Type % to find a matching ),], or } . **
442
443 1. Place the cursor on any (, [, or { in the line below marked --->.
444
445 2. Now type the % character.
446
447 3. The cursor should be on the matching parenthesis or bracket.
448
449 4. Type % to move the cursor back to the first bracket (by matching).
450
451 ---> This ( is a test line with ('s, ['s ] and {'s } in it. ))
452
453 Note: This is very useful in debugging a program with unmatched parentheses!
454
455
456
457
458
459
460 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
461 Lesson 4.4: A WAY TO CHANGE ERRORS
462
463
464 ** Type :s/old/new/g to substitute 'new' for 'old'. **
465
466 1. Move the cursor to the line below marked --->.
467
468 2. Type :s/thee/the <ENTER> . Note that this command only changes the
469 first occurrence on the line.
470
471 3. Now type :s/thee/the/g meaning substitute globally on the line.
472 This changes all occurrences on the line.
473
474 ---> thee best time to see thee flowers is in thee spring.
475
476 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.
478 Type :%s/old/new/g to change every occurrence in the whole file.
479
480
481
482
483 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
484 LESSON 4 SUMMARY
485
486
487 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
489 by Shift-G moves to that line number.
490
491 2. Typing / followed by a phrase searches FORWARD for the phrase.
492 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
494 or Shift-N to search in the opposite direction.
495
496 3. Typing % while the cursor is on a (,),[,],{, or } locates its
497 matching pair.
498
499 4. To substitute new for the first old on a line type :s/old/new
500 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
502 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
504
505
506 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
507 Lesson 5.1: HOW TO EXECUTE AN EXTERNAL COMMAND
508
509
510 ** Type :! followed by an external command to execute that command. **
511
512 1. Type the familiar command : to set the cursor at the bottom of the
513 screen. This allows you to enter a command.
514
515 2. Now type the ! (exclamation point) character. This allows you to
516 execute any external shell command.
517
518 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
520 shell prompt. Or use :!dir if ls doesn't work.
521
522 Note: It is possible to execute any external command this way.
523
524 Note: All : commands must be finished by hitting <ENTER>
525
526
527
528
529 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
530 Lesson 5.2: MORE ON WRITING FILES
531
532
533 ** To save the changes made to the file, type :w FILENAME. **
534
535 1. Type :!dir or :!ls to get a listing of your directory.
536 You already know you must hit <ENTER> after this.
537
538 2. Choose a filename that does not exist yet, such as TEST.
539
540 3. Now type: :w TEST (where TEST is the filename you chose.)
541
542 4. This saves the whole file (Vim Tutor) under the name TEST.
543 To verify this, type :!dir again to see your directory
544
545 Note: If you were to exit Vim and enter again with the filename TEST, the file
546 would be an exact copy of the tutor when you saved it.
547
548 5. Now remove the file by typing (MS-DOS): :!del TEST
549 or (Unix): :!rm TEST
550
551
552 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
553 Lesson 5.3: A SELECTIVE WRITE COMMAND
554
555
556 ** To save part of the file, type :#,# w FILENAME **
557
558 1. Once again, type :!dir or :!ls to obtain a listing of your directory
559 and choose a suitable filename such as TEST.
560
561 2. Move the cursor to the top of this page and type Ctrl-g to find the
562 number of that line. REMEMBER THIS NUMBER!
563
564 3. Now move to the bottom of the page and type Ctrl-g again. REMEMBER THIS
565 LINE NUMBER ALSO!
566
567 4. To save ONLY a section to a file, type :#,# w TEST where #,# are
568 the two numbers you remembered (top,bottom) and TEST is your filename.
569
570 5. Again, see that the file is there with :!dir but DO NOT remove it.
571
572
573
574
575 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
576 Lesson 5.4: RETRIEVING AND MERGING FILES
577
578
579 ** To insert the contents of a file, type :r FILENAME **
580
581 1. Type :!dir to make sure your TEST filename is present from before.
582
583 2. Place the cursor at the top of this page.
584
585 NOTE: After executing Step 3 you will see Lesson 5.3. Then move DOWN to
586 this lesson again.
587
588 3. Now retrieve your TEST file using the command :r TEST where TEST is
589 the name of the file.
590
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.
595
596
597
598 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
599 LESSON 5 SUMMARY
600
601
602 1. :!command executes an external command.
603
604 Some useful examples are:
605 (MS-DOS) (Unix)
606 :!dir :!ls - shows a directory listing.
607 :!del FILENAME :!rm FILENAME - removes file FILENAME.
608
609 2. :w FILENAME writes the current Vim file to disk with name FILENAME.
610
611 3. :#,#w FILENAME saves the lines # through # in file FILENAME.
612
613 4. :r FILENAME retrieves disk file FILENAME and inserts it into the
614 current file following the cursor position.
615
616
617
618
619
620
621 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
622 Lesson 6.1: THE OPEN COMMAND
623
624
625 ** Type o to open a line below the cursor and place you in Insert mode. **
626
627 1. Move the cursor to the line below marked --->.
628
629 2. Type o (lowercase) to open up a line BELOW the cursor and place you in
630 Insert mode.
631
632 3. Now copy the line marked ---> and press <ESC> to exit Insert mode.
633
634 ---> After typing o the cursor is placed on the open line in Insert mode.
635
636 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.
638 Open up a line above this by typing Shift-O while the cursor is on this line.
639
640
641
642
643
644 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
645 Lesson 6.2: THE APPEND COMMAND
646
647
648 ** Type a to insert text AFTER the cursor. **
649
650 1. Move the cursor to the end of the first line below marked ---> by
651 typing $ in Normal mode.
652
653 2. Type an a (lowercase) to append text AFTER the character under the
654 cursor. (Uppercase A appends to the end of the line.)
655
656 Note: This avoids typing i , the last character, the text to insert, <ESC>,
657 cursor-right, and finally, x , just to append to the end of a line!
658
659 3. Now complete the first line. Note also that append is exactly the same
660 as Insert mode, except for the location where text is inserted.
661
662 ---> This line will allow you to practice
663 ---> This line will allow you to practice appending text to the end of a line.
664
665
666
667 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
668 Lesson 6.3: ANOTHER VERSION OF REPLACE
669
670
671 ** Type a capital R to replace more than one character. **
672
673 1. Move the cursor to the first line below marked --->.
674
675 2. Place the cursor at the beginning of the first word that is different
676 from the second line marked ---> (the word 'last').
677
678 3. Now type R and replace the remainder of the text on the first line by
679 typing over the old text to make the first line the same as the second.
680
681 ---> To make the first line the same as the last on this page use the keys.
682 ---> To make the first line the same as the second, type R and the new text.
683
684 4. Note that when you press <ESC> to exit, any unaltered text remains.
685
686
687
688
689
690 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
691 Lesson 6.4: SET OPTION
692
693 ** Set an option so a search or substitute ignores case **
694
695 1. Search for 'ignore' by entering:
696 /ignore
697 Repeat several times by hitting the n key
698
699 2. Set the 'ic' (Ignore case) option by typing:
700 :set ic
701
702 3. Now search for 'ignore' again by entering: n
703 Repeat search several more times by hitting the n key
704
705 4. Set the 'hlsearch' and 'incsearch' options:
706 :set hls is
707
708 5. Now enter the search command again, and see what happens:
709 /ignore
710
711 6. To remove the highlighting of matches, type:
712 :nohlsearch
713 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
714 LESSON 6 SUMMARY
715
716
717 1. Typing o opens a line BELOW the cursor and places the cursor on the open
718 line in Insert mode.
719 Typing a capital O opens the line ABOVE the line the cursor is on.
720
721 2. Type an a to insert text AFTER the character the cursor is on.
722 Typing a capital A automatically appends text to the end of the line.
723
724 3. Typing a capital R enters Replace mode until <ESC> is pressed to exit.
725
726 4. Typing ":set xxx" sets the option "xxx"
727
728
729
730
731
732
733
734
735
736 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
737 LESSON 7: ON-LINE HELP COMMANDS
738
739
740 ** Use the on-line help system **
741
742 Vim has a comprehensive on-line help system. To get started, try one of
743 these three:
744 - press the <HELP> key (if you have one)
745 - press the <F1> key (if you have one)
746 - type :help <ENTER>
747
748 Type :q <ENTER> to close the help window.
749
750 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>):
752
753 :help w
754 :help c_<T
755 :help insert-index
756 :help user-manual
757
758
759 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
760 LESSON 8: CREATE A STARTUP SCRIPT
761
762 ** Switch on Vim features **
763
764 Vim has many more features than Vi, but most of them are disabled by default.
765 To start using more features you have to create a "vimrc" file.
766
767 1. Start editing the "vimrc" file, this depends on your system:
768 :edit ~/.vimrc for Unix
769 :edit $VIM/_vimrc for MS-Windows
770
771 2. Now read the example "vimrc" file text:
772
773 :read $VIMRUNTIME/vimrc_example.vim
774
775 3. Write the file with:
776
777 :write
778
779 The next time you start Vim it will use syntax highlighting.
780 You can add all your preferred settings to this "vimrc" file.
781
782 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
783
784 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.
786 It is far from complete as Vim has many many more commands. Read the user
787 manual next: ":help user-manual".
788
789 For further reading and studying, this book is recommended:
790 Vim - Vi Improved - by Steve Oualline
791 Publisher: New Riders
792 The first book completely dedicated to Vim. Especially useful for beginners.
793 There are many examples and pictures.
794 See http://iccf-holland.org/click5.html
795
796 This book is older and more about Vi than Vim, but also recommended:
797 Learning the Vi Editor - by Linda Lamb
798 Publisher: O'Reilly & Associates Inc.
799 It is a good book to get to know almost anything you want to do with Vi.
800 The sixth edition also includes information on Vim.
801
802 This tutorial was written by Michael C. Pierce and Robert K. Ware,
803 Colorado School of Mines using ideas supplied by Charles Smith,
804 Colorado State University. E-mail: bware@mines.colorado.edu.
805
806 Modified for Vim by Bram Moolenaar.
807
808 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~