-
Notifications
You must be signed in to change notification settings - Fork 16
/
vim_1_white.master
823 lines (522 loc) · 26.3 KB
/
vim_1_white.master
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
-----------------------------------------------------------------------------+
| Vim Kata - White Belt (Level 1) |
+-----------------------------------------------------------------------------+
Welcome, young Vim warrior. It is an honor to meet someone such as yourself
who seeks more than a mere grasping of a few concepts along the Vim path. If
you discipline your mind and dedicate yourself to the practice of Vim Kata,
you will learn to edit text like you touch type. You will feel the flow of
the text in you, and around you, and by your will you will bend its shape and
cause it to flow as you see fit. If you continue to apply yourself and repeat
the kata each day, then before long, you will join the few who have become
Masters of Vim.
Each practice session--called a 'kata'--should take about 20 minutes, or a
little more if it is your first time. When you have reduced the time to under
5 minutes, you should move on to the next kata.
You will find the answer to each question marked by a '>'. You should be able
to type the answer exactly and get the correct result. Each answer assumes that
your cursor is positioned on the first character of the line below the question
Tip: Press 'j' to move down.
Tip: To quit this kata at any time, press <ESC>:q! and then press enter.
Pressing <ESC>:q! will discard any changes.
+-----------------------------------------------------------------------------+
| Ready? Begin! |
+-----------------------------------------------------------------------------+
(#) Follow the path from 'o' to 'x':
o-| x-----------|
|-| |-| |----| |
|--| | | |--| | |
|----| |----| |-|
> lljlljhhhjlllllkklljjlllllkhhhkllllljjllkkkhhhhhhhhhhhh
(#) Using 'l' and 'i' keys, insert the missing text in line 1 using line 2 as a guide:
DlbraePrate
Deliberate Practice
> lielliillielllitlli lllliclliic
(#) Using 'h' and 'a' keys, insert the missing text in line 1 using line 2 as a guide
Repttion s Wrtwhil
Repetition is Worthwhile
< $
> aehhhhhahhhhaohhhhaihhhhhhaihhae
(#) Follow the path from 'o' to 'x':
|--------x
| |----------|
| | |------| |
| | | |--| | |
| | | | | | |
| | |-| o | |
| | |-|
|-|
< /o:noh
> kkhhhjjhhkkkllllllljjjjllkkkkkhhhhhhhhhhhjjjjjjhhkkkkkkklllllllll
(#) Using 'A', append each parenthetical word to the end of its line:
(not) Seek
(the) to follow in
(old;) footsteps of men of
(sought.) seek what they
~ Matsu Basho
> A notjA thejA old;jA sought.
(#) Using 'l' and 'i' keys, insert the missing text in line 1 using line 2 as a guide:
A atais Wort a Tousad Eis
A Kata is Worth a Thousand Edits
> lliKlllli llllllllihlllllihlllllinllllidllit
(#) Using 'h' and 'i' keys, insert the missing text in line 1 using line 2 as a guide
Kep t Simle Smart
Keep It Simple Smarty
< $
> ithhhhhhhiphhhhhiIhhie
(#) Follow the words in alphabetical order (touch each FIRST letter):
Alpha Bravo Charlie Mike November
Echo Delta Lima Kilo
Foxtrot India Juliet
Golf Hotel
> wwjbjjwkwkbkw
(#) Follow the words in alphabetical order (touch each FIRST letter):
Foxtrot, "Golf" Hotel... India
Echo Bravo? Alpha Juliet
Delta! Charlie Lima
< /Alpha:noh
> BjBkkWWWjj
(#) Using 'e' and 'a', pluralize the following words:
Canadian Shark Deliver Wedding Discover
> easeaseaseaseas
(#) Using 'w' and 'i', prefix each word with 'pre':
history meditate view disposition pare
> iprewiprewiprewiprewipre
(#) Using :s, prefix each word with 'pre':
history meditate view disposition pare
> :s/\>/pre/g
(#) Delete the following CAPITALIZED words (including any connected punctuation):
NO life EVER grows great UNTIL IT is FOCUSED, DEDICATED AND disciplined.
> dwwdwwwdwdwwdWdwdw
(#) Delete from the '|' to the end of the line:
The weakest of all |weak things is a virtue that has not been tested in the fire.
~ Mark Twain
> 4wD
(#) Delete the following CAPITALIZED words (including any connected punctuation):
NEVER INTERRUPT YOUR ENEMY WHEN he is making a mistake.
~ Napoleon Bonaparte
> d5w
(#) Delete the following CAPITALIZED words (including any connected punctuation):
Never interrupt your enemy WHEN HE IS MAKING A MISTAKE.
~ Napoleon Bonaparte
> 4wD
(#) Delete the entire line without moving the cursor:
We are what we repeatedly do. Excellence then, is not an act, but a habit.
~ Aristotle
< 6W
> dd
(#) Delete all three lines:
I fear not the man who has practiced 10,000 kicks once,
but I fear the man who has practiced one kick 10,000 times.
~ Bruce Lee
> d3d
(#) Delete the UPPER CASE words:
Never AB CDEF interrupt your GHIJKL MNOP QRS enemy when he TUVWXYZ is making a mistake.
~ Napoleon Bonaparte
> w2dwww3dwwwwdw
(#) Delete every second word, then undo all changes to the line:
A warrior may choose pacifism; others are condemned to it.
> wdwwdwWdwwdwwdwU
(#) Delete every CAPITALIZED word, undo the deletions, then redo them all:
Begin at THE beginning, the KING said, gravely,
and go on till YOU come to the end: then stop.
~ Lewis CAROLL
> wwdwWWdw6Wdw8Wdwuuuu
(#) Delete the middle line and put a copy of it above and below the other two:
(
Middle Line
)
(
Do it again
)
(
Seek not to follow in the footsteps of men of old; seek what they sought.
)
< 2j
> ddpkkP}jjddpkkP}jjddpkkP
(#) Using dd and p, put the following lines in the correct order:
3. and dissolve the principle.
7. ~ Bruce Lee
1. Learn the principle,
4. In short, enter a mold without being caged in it.
2. abide by the principle,
6. Learn, master and achieve!
5. Obey the principle without being bound by it.
> ddjpkkdd5jp3kddkkPjjjddp
(#) Using !sort, put the following lines in the correct order:
3. and dissolve the principle.
7. ~ Bruce Lee
1. Learn the principle,
4. In short, enter a mold without being caged in it.
2. abide by the principle,
6. Learn, master and achieve!
5. Obey the principle without being bound by it.
> V6j:!sort
(#) Using 'r', correct the following typos and spelling mistakes:
Giwe piople a chamce to meke a dIfferense in the worlt.
> llrvllllrelllllllllllrnllllllllralllllllrilllllllrcllllllllllllllrd
(#) Using 'r', follow the path and fill in the missing numbers:
1-2 -7-8 7-8-
| | | |
3- -5
| |
6- -4- -2-1 5
| |
-8-9-1- -3-
> lljjllr4llkkr6lllljjr9jjhhhhr3hhhhr5hhjjr7llllllllr2llllr4kkkkr6kkllllr9
(#) Using 'c' combinations, change the CAPITALIZED words to the word in parentheses:
a CHIMPANZEE in the hand is worth two in the bush
(bird)
keep your STOMACH in the present
(heart)
and your NOSE in the future
(eye)
> wcwbirdjjjwcwheartjjjbcweye
(#) Using 'C', change the CAPITALIZED words up the end of the line:
excellence is our INHERENT RIGHT
(goal)
deliberate practice is what we WATCH OTHER PEOPLE DO
(praise)
we are not our COLLECTION OF TOYS
(thoughts)
may all beings be free from the causes of THOUGHTLESS BEHAVIOR
(suffering)
> wwwCgoaljjjwwwCpraisejjjbbbCthoughtsjjjwwwwwCsuffering
(#) Using 'c' and 't', change the CAPITALIZED words up to a certain character:
may you live a REMARKABLY OSTENTATIOUS, healthy life
(long)
if dict["WORD OR GROUP OF WORDS"] == "definition"
(phrase)
education is a WILDLY POPULAR EXPERIENCE, not an outcome
(process)
with (CRAZY LONG VARIABLE) do
(i)
> wwwwct,longjjjbbbct"phrasejjjwct,processjjjbbbct)i
+-----------------------------------------------------------------------------+
| Sparring Time! |
+-----------------------------------------------------------------------------+
At this point in the lesson, you have done a number of repetitive exercises.
Now, try your hand against several randomly chosen questions that further
stretch your developing muscle memory. Go as fast as you can!
! KataRandom(movement-along-a-path)
! KataRandom(move-and-delete)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 3.4: MORE CHANGES USING c
** The change operator is used with the same motions as delete. **
1. The change operator works in the same way as delete. The format is:
c [number] motion
2. The motions are the same, such as w (word) and $ (end of line).
3. Move to the first line below marked --->.
4. Move the cursor to the first error.
5. Type c$ and type the rest of the line like the second and press <ESC>.
---> The end of this line needs some help to make it like the second.
---> The end of this line needs to be corrected using the c$ command.
NOTE: You can use the Backspace key to correct mistakes while typing.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 3 SUMMARY
1. To put back text that has just been deleted, type p . This puts the
deleted text AFTER the cursor (if a line was deleted it will go on the
line below the cursor).
2. To replace the character under the cursor, type r and then the
character you want to have there.
3. The change operator allows you to change from the cursor to where the
motion takes you. eg. Type ce to change from the cursor to the end of
the word, c$ to change to the end of a line.
4. The format for change is:
c [number] motion
Now go on to the next lesson.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.1: CURSOR LOCATION AND FILE STATUS
** Type CTRL-G to show your location in the file and the file status.
Type G to move to a line in the file. **
NOTE: Read this entire lesson before executing any of the steps!!
1. Hold down the Ctrl key and press g . We call this CTRL-G.
A message will appear at the bottom of the page with the filename and the
position in the file. Remember the line number for Step 3.
NOTE: You may see the cursor position in the lower right corner of the screen
This happens when the 'ruler' option is set (see :help 'ruler' )
2. Press G to move you to the bottom of the file.
Type gg to move you to the start of the file.
3. Type the number of the line you were on and then G . This will
return you to the line you were on when you first pressed CTRL-G.
4. If you feel confident to do this, execute steps 1 through 3.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.2: THE SEARCH COMMAND
** Type / followed by a phrase to search for the phrase. **
1. In Normal mode type the / character. Notice that it and the cursor
appear at the bottom of the screen as with the : command.
2. Now type 'errroor' <ENTER>. This is the word you want to search for.
3. To search for the same phrase again, simply type n .
To search for the same phrase in the opposite direction, type N .
4. To search for a phrase in the backward direction, use ? instead of / .
5. To go back to where you came from press CTRL-O (Keep Ctrl down while
pressing the letter o). Repeat to go back further. CTRL-I goes forward.
---> "errroor" is not the way to spell error; errroor is an error.
NOTE: When the search reaches the end of the file it will continue at the
start, unless the 'wrapscan' option has been reset.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.3: MATCHING PARENTHESES SEARCH
** Type % to find a matching ),], or } . **
1. Place the cursor on any (, [, or { in the line below marked --->.
2. Now type the % character.
3. The cursor will move to the matching parenthesis or bracket.
4. Type % to move the cursor to the other matching bracket.
5. Move the cursor to another (,),[,],{ or } and see what % does.
---> This ( is a test line with ('s, ['s ] and {'s } in it. ))
NOTE: This is very useful in debugging a program with unmatched parentheses!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.4: THE SUBSTITUTE COMMAND
** Type :s/old/new/g to substitute 'new' for 'old'. **
1. Move the cursor to the line below marked --->.
2. Type :s/thee/the <ENTER> . Note that this command only changes the
first occurrence of "thee" in the line.
3. Now type :s/thee/the/g . Adding the g flag means to substitute
globally in the line, change all occurrences of "thee" in the line.
---> thee best time to see thee flowers is in thee spring.
4. To change every occurrence of a character string between two lines,
type :#,#s/old/new/g where #,# are the line numbers of the range
of lines where the substitution is to be done.
Type :%s/old/new/g to change every occurrence in the whole file.
Type :%s/old/new/gc to find every occurrence in the whole file,
with a prompt whether to substitute or not.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4 SUMMARY
1. CTRL-G displays your location in the file and the file status.
G moves to the end of the file.
number G moves to that line number.
gg moves to the first line.
2. Typing / followed by a phrase searches FORWARD for the phrase.
Typing ? followed by a phrase searches BACKWARD for the phrase.
After a search type n to find the next occurrence in the same direction
or N to search in the opposite direction.
CTRL-O takes you back to older positions, CTRL-I to newer positions.
3. Typing % while the cursor is on a (,),[,],{, or } goes to its match.
4. To substitute new for the first old in a line type :s/old/new
To substitute new for all 'old's on a line type :s/old/new/g
To substitute phrases between two line #'s type :#,#s/old/new/g
To substitute all occurrences in the file type :%s/old/new/g
To ask for confirmation each time add 'c' :%s/old/new/gc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.1: HOW TO EXECUTE AN EXTERNAL COMMAND
** Type :! followed by an external command to execute that command. **
1. Type the familiar command : to set the cursor at the bottom of the
screen. This allows you to enter a command-line command.
2. Now type the ! (exclamation point) character. This allows you to
execute any external shell command.
3. As an example type ls following the ! and then hit <ENTER>. This
will show you a listing of your directory, just as if you were at the
shell prompt. Or use :!dir if ls doesn't work.
NOTE: It is possible to execute any external command this way, also with
arguments.
NOTE: All : commands must be finished by hitting <ENTER>
From here on we will not always mention it.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.2: MORE ON WRITING FILES
** To save the changes made to the text, type :w FILENAME. **
1. Type :!dir or :!ls to get a listing of your directory.
You already know you must hit <ENTER> after this.
2. Choose a filename that does not exist yet, such as TEST.
3. Now type: :w TEST (where TEST is the filename you chose.)
4. This saves the whole file (the Vim Tutor) under the name TEST.
To verify this, type :!dir or :!ls again to see your directory.
NOTE: If you were to exit Vim and start it again with vim TEST , the file
would be an exact copy of the tutor when you saved it.
5. Now remove the file by typing (MS-DOS): :!del TEST
or (Unix): :!rm TEST
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.3: SELECTING TEXT TO WRITE
** To save part of the file, type v motion :w FILENAME **
1. Move the cursor to this line.
2. Press v and move the cursor to the fifth item below. Notice that the
text is highlighted.
3. Press the : character. At the bottom of the screen :'<,'> will appear.
4. Type w TEST , where TEST is a filename that does not exist yet. Verify
that you see :'<,'>w TEST before you press Enter.
5. Vim will write the selected lines to the file TEST. Use :!dir or !ls
to see it. Do not remove it yet! We will use it in the next lesson.
NOTE: Pressing v starts Visual selection. You can move the cursor around
to make the selection bigger or smaller. Then you can use an operator
to do something with the text. For example, d deletes the text.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.4: RETRIEVING AND MERGING FILES
** To insert the contents of a file, type :r FILENAME **
1. Place the cursor just above this line.
NOTE: After executing Step 2 you will see text from Lesson 5.3. Then move
DOWN to see this lesson again.
2. Now retrieve your TEST file using the command :r TEST where TEST is
the name of the file you used.
The file you retrieve is placed below the cursor line.
3. To verify that a file was retrieved, cursor back and notice that there
are now two copies of Lesson 5.3, the original and the file version.
NOTE: You can also read the output of an external command. For example,
:r !ls reads the output of the ls command and puts it below the
cursor.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5 SUMMARY
1. :!command executes an external command.
Some useful examples are:
(MS-DOS) (Unix)
:!dir :!ls - shows a directory listing.
:!del FILENAME :!rm FILENAME - removes file FILENAME.
2. :w FILENAME writes the current Vim file to disk with name FILENAME.
3. v motion :w FILENAME saves the Visually selected lines in file
FILENAME.
4. :r FILENAME retrieves disk file FILENAME and puts it below the
cursor position.
5. :r !dir reads the output of the dir command and puts it below the
cursor position.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.1: THE OPEN COMMAND
** Type o to open a line below the cursor and place you in Insert mode. **
1. Move the cursor to the line below marked --->.
2. Type the lowercase letter o to open up a line BELOW the cursor and place
you in Insert mode.
3. Now type some text and press <ESC> to exit Insert mode.
---> After typing o the cursor is placed on the open line in Insert mode.
4. To open up a line ABOVE the cursor, simply type a capital O , rather
than a lowercase o. Try this on the line below.
---> Open up a line above this by typing O while the cursor is on this line.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.2: THE APPEND COMMAND
** Type a to insert text AFTER the cursor. **
1. Move the cursor to the start of the line below marked --->.
2. Press e until the cursor is on the end of li .
3. Type an a (lowercase) to append text AFTER the cursor.
4. Complete the word like the line below it. Press <ESC> to exit Insert
mode.
5. Use e to move to the next incomplete word and repeat steps 3 and 4.
---> This li will allow you to pract appendi text to a line.
---> This line will allow you to practice appending text to a line.
NOTE: a, i and A all go to the same Insert mode, the only difference is where
the characters are inserted.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.3: ANOTHER WAY TO REPLACE
** Type a capital R to replace more than one character. **
1. Move the cursor to the first line below marked --->. Move the cursor to
the beginning of the first xxx .
2. Now press R and type the number below it in the second line, so that it
replaces the xxx .
3. Press <ESC> to leave Replace mode. Notice that the rest of the line
remains unmodified.
4. Repeat the steps to replace the remaining xxx.
---> Adding 123 to xxx gives you xxx.
---> Adding 123 to 456 gives you 579.
NOTE: Replace mode is like Insert mode, but every typed character deletes an
existing character.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.4: COPY AND PASTE TEXT
** Use the y operator to copy text and p to paste it **
1. Go to the line marked with ---> below and place the cursor after "a)".
2. Start Visual mode with v and move the cursor to just before "first".
3. Type y to yank (copy) the highlighted text.
4. Move the cursor to the end of the next line: j$
5. Type p to put (paste) the text. Then type: a second <ESC> .
6. Use Visual mode to select " item.", yank it with y , move to the end of
the next line with j$ and put the text there with p .
---> a) this is the first item.
b)
NOTE: you can also use y as an operator; yw yanks one word.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.5: SET OPTION
** Set an option so a search or substitute ignores case **
1. Search for 'ignore' by entering: /ignore <ENTER>
Repeat several times by pressing n .
2. Set the 'ic' (Ignore case) option by entering: :set ic
3. Now search for 'ignore' again by pressing n
Notice that Ignore and IGNORE are now also found.
4. Set the 'hlsearch' and 'incsearch' options: :set hls is
5. Now type the search command again and see what happens: /ignore <ENTER>
6. To disable ignoring case enter: :set noic
NOTE: To remove the highlighting of matches enter: :nohlsearch
NOTE: If you want to ignore case for just one search command, use \c
in the phrase: /ignore\c <ENTER>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6 SUMMARY
1. Type o to open a line BELOW the cursor and start Insert mode.
Type O to open a line ABOVE the cursor.
2. Type a to insert text AFTER the cursor.
Type A to insert text after the end of the line.
3. The e command moves to the end of a word.
4. The y operator yanks (copies) text, p puts (pastes) it.
5. Typing a capital R enters Replace mode until <ESC> is pressed.
6. Typing ":set xxx" sets the option "xxx". Some options are:
'ic' 'ignorecase' ignore upper/lower case when searching
'is' 'incsearch' show partial matches for a search phrase
'hls' 'hlsearch' highlight all matching phrases
You can either use the long or the short option name.
7. Prepend "no" to switch an option off: :set noic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 7.1: GETTING HELP
** Use the on-line help system **
Vim has a comprehensive on-line help system. To get started, try one of
these three:
- press the <HELP> key (if you have one)
- press the <F1> key (if you have one)
- type :help <ENTER>
Read the text in the help window to find out how the help works.
Type CTRL-W CTRL-W to jump from one window to another.
Type :q <ENTER> to close the help window.
You can find help on just about any subject, by giving an argument to the
":help" command. Try these (don't forget pressing <ENTER>):
:help w
:help c_CTRL-D
:help insert-index
:help user-manual
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 7.2: CREATE A STARTUP SCRIPT
** Enable Vim features **
Vim has many more features than Vi, but most of them are disabled by
default. To start using more features you have to create a "vimrc" file.
1. Start editing the "vimrc" file. This depends on your system:
:e ~/.vimrc for Unix
:e $VIM/_vimrc for MS-Windows
2. Now read the example "vimrc" file contents:
:r $VIMRUNTIME/vimrc_example.vim
3. Write the file with:
:w
The next time you start Vim it will use syntax highlighting.
You can add all your preferred settings to this "vimrc" file.
For more information type :help vimrc-intro
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 7.3: COMPLETION
** Command line completion with CTRL-D and <TAB> **
1. Make sure Vim is not in compatible mode: :set nocp
2. Look what files exist in the directory: :!ls or :!dir
3. Type the start of a command: :e
4. Press CTRL-D and Vim will show a list of commands that start with "e".
5. Press <TAB> and Vim will complete the command name to ":edit".
6. Now add a space and the start of an existing file name: :edit FIL
7. Press <TAB>. Vim will complete the name (if it is unique).
NOTE: Completion works for many commands. Just try pressing CTRL-D and
<TAB>. It is especially useful for :help .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 7 SUMMARY
1. Type :help or press <F1> or <Help> to open a help window.
2. Type :help cmd to find help on cmd .
3. Type CTRL-W CTRL-W to jump to another window
4. Type :q to close the help window
5. Create a vimrc startup script to keep your preferred settings.
6. When typing a : command, press CTRL-D to see possible completions.
Press <TAB> to use one completion.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This concludes the Vim Tutor. It was intended to give a brief overview of
the Vim editor, just enough to allow you to use the editor fairly easily.
It is far from complete as Vim has many many more commands. Read the user
manual next: ":help user-manual".
For further reading and studying, this book is recommended:
Vim - Vi Improved - by Steve Oualline
Publisher: New Riders
The first book completely dedicated to Vim. Especially useful for beginners.
There are many examples and pictures.
See http://iccf-holland.org/click5.html
This book is older and more about Vi than Vim, but also recommended:
Learning the Vi Editor - by Linda Lamb
Publisher: O'Reilly & Associates Inc.
It is a good book to get to know almost anything you want to do with Vi.
The sixth edition also includes information on Vim.
This tutorial was written by Michael C. Pierce and Robert K. Ware,
Colorado School of Mines using ideas supplied by Charles Smith,
Colorado State University. E-mail: [email protected].
Modified for Vim by Bram Moolenaar.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~