Skip to content

Commit 2323f22

Browse files
RestorerZchrisbra
authored andcommitted
runtime(new-tutor): add chapter two to the interactive tutorial
closes: #16803 Signed-off-by: RestorerZ <restorer@mail2k.ru> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 34a7d82 commit 2323f22

File tree

5 files changed

+256
-45
lines changed

5 files changed

+256
-45
lines changed

Filelist

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -771,16 +771,16 @@ RT_ALL = \
771771
runtime/tools/[a-z]*[a-z0-9] \
772772
runtime/tutor/README.txt \
773773
runtime/tutor/tutor1 \
774+
runtime/tutor/tutor1.utf-8 \
774775
runtime/tutor/en/vim-01-beginner.tutor \
775776
runtime/tutor/en/vim-01-beginner.tutor.json \
776-
runtime/tutor/it/vim-01-beginner.tutor \
777-
runtime/tutor/it/vim-01-beginner.tutor.json \
778-
runtime/tutor/sr/vim-01-beginner.tutor \
779-
runtime/tutor/sr/vim-01-beginner.tutor.json \
777+
runtime/tutor/en/vim-02-beginner.tutor \
778+
runtime/tutor/en/vim-02-beginner.tutor.json \
780779
runtime/tutor/tutor.tutor \
781780
runtime/tutor/tutor.tutor.json \
782781
runtime/tutor/tutor.vim \
783782
runtime/tutor/tutor2 \
783+
runtime/tutor/tutor2.utf-8 \
784784
runtime/vimrc_example.vim \
785785
runtime/pack/dist/opt/cfilter/plugin/cfilter.vim \
786786
runtime/pack/dist/opt/comment/plugin/comment.vim \
@@ -1077,7 +1077,10 @@ LANG_GEN = \
10771077
runtime/tutor/README.*.txt \
10781078
runtime/tutor/Makefile \
10791079
runtime/tutor/Make_all.mak \
1080-
runtime/tutor/tutor1.utf-8 \
1080+
runtime/tutor/it/vim-01-beginner.tutor \
1081+
runtime/tutor/it/vim-01-beginner.tutor.json \
1082+
runtime/tutor/sr/vim-01-beginner.tutor \
1083+
runtime/tutor/sr/vim-01-beginner.tutor.json \
10811084
runtime/tutor/tutor1.?? \
10821085
runtime/tutor/tutor1.??.utf-8 \
10831086
runtime/tutor/tutor1.??.euc \
@@ -1090,7 +1093,6 @@ LANG_GEN = \
10901093
runtime/tutor/tutor1.??_??.utf-8 \
10911094
runtime/tutor/tutor1.bar \
10921095
runtime/tutor/tutor1.bar.utf-8 \
1093-
runtime/tutor/tutor2.utf-8 \
10941096
runtime/tutor/tutor2.?? \
10951097
runtime/tutor/tutor2.??.utf-8 \
10961098
runtime/spell/README.txt \

runtime/tutor/en/vim-01-beginner.tutor

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Welcome to the VIM Tutor
22

3+
# CHAPTER ONE
4+
35
Vim is a very powerful editor that has many commands, too many to explain in
46
a tutor such as this. This tutor is designed to describe enough of the
57
commands that you will be able to easily use Vim as an all-purpose editor.
@@ -38,7 +40,7 @@ instead of text to type.
3840

3941
Now, move to the next lesson (use the `j`{normal} key to scroll down).
4042

41-
## Lesson 1.1: MOVING THE CURSOR
43+
# Lesson 1.1: MOVING THE CURSOR
4244

4345
** To move the cursor, press the `h`, `j`, `k`, `l` keys as indicated. **
4446

@@ -87,7 +89,7 @@ NOTE: [:q!](:q) <Enter> discards any changes you made. In a few lessons you
8789

8890
5. Move the cursor down to Lesson 1.3.
8991

90-
## Lesson 1.3: TEXT EDITING - DELETION
92+
# Lesson 1.3: TEXT EDITING - DELETION
9193

9294
** Press `x`{normal} to delete the character under the cursor. **
9395

@@ -430,7 +432,7 @@ Notice that [c](c)e deletes the word and places you in Insert mode.
430432
5. Type `c$`{normal} and type the rest of the line like the second and press `<Esc>`{normal}.
431433

432434
The end of this line needs some help to make it like the second.
433-
The end of this line needs to be corrected using the `c$`{normal} command.
435+
The end of this line needs to be corrected using the c$ command.
434436

435437
NOTE: You can use the Backspace key to correct mistakes while typing.
436438

@@ -907,8 +909,8 @@ Vim has many more features than Vi, but most of them are disabled by
907909
default. To start using more features you have to create a "vimrc" file.
908910

909911
1. Start editing the "vimrc" file. This depends on your system:
910-
for UNIX-like for Windows
911-
`:e ~/.vimrc`{vim} `:e ~/_vimrc`{vim}
912+
for UNIX-like for Windows
913+
`:e ~/.vimrc`{vim} `:e ~/_vimrc`{vim}
912914

913915
2. Now read the example "vimrc" file contents:
914916
`:r $VIMRUNTIME/vimrc_example.vim`{vim}
@@ -958,6 +960,9 @@ NOTE: Completion works for many commands. It is especially useful for
958960

959961
# CONCLUSION
960962

963+
This concludes Chapter 1 of the Vim Tutor. Consider continuing with
964+
[Chapter 2](@tutor:tutor:vim-02-beginner).
965+
961966
This was intended to give a brief overview of the Vim editor, just enough to
962967
allow you to use the editor fairly easily. It is far from complete as Vim has
963968
many many more commands. Consult the help often.
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
{
22
"expect": {
3-
"24": -1,
4-
"103": "The cow jumped over the moon.",
5-
"124": "There is some text missing from this line.",
6-
"125": "There is some text missing from this line.",
7-
"144": "There is some text missing from this line.",
8-
"145": "There is some text missing from this line.",
9-
"146": "There is also some text missing here.",
10-
"147": "There is also some text missing here.",
11-
"220": "There are some words that don't belong in this sentence.",
12-
"236": "Somebody typed the end of this line twice.",
13-
"276": -1,
14-
"295": "This line of words is cleaned up.",
15-
"309": -1,
16-
"310": -1,
3+
"26": -1,
4+
"105": "The cow jumped over the moon.",
5+
"126": "There is some text missing from this line.",
6+
"127": "There is some text missing from this line.",
7+
"146": "There is some text missing from this line.",
8+
"147": "There is some text missing from this line.",
9+
"148": "There is also some text missing here.",
10+
"149": "There is also some text missing here.",
11+
"222": "There are some words that don't belong in this sentence.",
12+
"238": "Somebody typed the end of this line twice.",
13+
"278": -1,
14+
"297": "This line of words is cleaned up.",
1715
"311": -1,
1816
"312": -1,
1917
"313": -1,
2018
"314": -1,
2119
"315": -1,
22-
"332": "Fix the errors on this line and replace them with undo.",
23-
"372": -1,
24-
"373": -1,
20+
"316": -1,
21+
"317": -1,
22+
"334": "Fix the errors on this line and replace them with undo.",
2523
"374": -1,
2624
"375": -1,
27-
"389": "When this line was typed in, someone pressed some wrong keys!",
28-
"390": "When this line was typed in, someone pressed some wrong keys!",
29-
"411": "This line has a few words that need changing using the change operator.",
30-
"412": "This line has a few words that need changing using the change operator.",
31-
"432": "The end of this line needs to be corrected using the `c$` command.",
32-
"433": "The end of this line needs to be corrected using the `c$` command.",
33-
"497": -1,
34-
"516": -1,
35-
"541": "Usually the best time to see the flowers is in the spring.",
36-
"735": -1,
37-
"740": -1,
38-
"759": "This line will allow you to practice appending text to a line.",
39-
"760": "This line will allow you to practice appending text to a line.",
40-
"780": "Adding 123 to 456 gives you 579.",
41-
"781": "Adding 123 to 456 gives you 579.",
42-
"807": "a) This is the first item.",
43-
"808": "b) This is the second item."
25+
"376": -1,
26+
"377": -1,
27+
"391": "When this line was typed in, someone pressed some wrong keys!",
28+
"392": "When this line was typed in, someone pressed some wrong keys!",
29+
"413": "This line has a few words that need changing using the change operator.",
30+
"414": "This line has a few words that need changing using the change operator.",
31+
"434": "The end of this line needs to be corrected using the c$ command.",
32+
"435": "The end of this line needs to be corrected using the c$ command.",
33+
"499": -1,
34+
"518": -1,
35+
"543": "Usually the best time to see the flowers is in the spring.",
36+
"737": -1,
37+
"742": -1,
38+
"761": "This line will allow you to practice appending text to a line.",
39+
"762": "This line will allow you to practice appending text to a line.",
40+
"782": "Adding 123 to 456 gives you 579.",
41+
"783": "Adding 123 to 456 gives you 579.",
42+
"809": "a) This is the first item.",
43+
"810": "b) This is the second item."
4444
}
4545
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# Welcome to the VIM Tutor
2+
3+
# CHAPTER TWO
4+
5+
Hic Sunt Dracones: if this is your first exposure to vim and you
6+
intended to avail yourself of the introductory chapter, kindly type
7+
on the command line of the Vim editor
8+
~~~ cmd
9+
:Tutor vim-01-beginner
10+
~~~
11+
Or just open the [first chapter](@tutor:vim-01-beginner) of the tutor at the link.
12+
13+
The approximate time required to complete this chapter is 8-10 minutes,
14+
depending upon how much time is spent with experimentation.
15+
16+
17+
# Lesson 2.1.1: THE NAMED REGISTERS
18+
19+
** Store two yanked words concurrently and then paste them **
20+
21+
1. Move the cursor to the line below marked ✓
22+
23+
2. Navigate to any point on the word 'Edward' and type `"ayiw`{normal}
24+
25+
**MNEMONIC**: *into register(") named (a) (y)ank (i)nner (w)ord*
26+
27+
3. Navigate forward to the word 'cookie' (`fk`{normal} or `2fc`{normal}
28+
or `$2b`{normal} or `/co`{normal} `<ENTER>`{normal}) and type `"byiw`{normal}
29+
30+
4. Navigate to any point on the word 'Vince' and type `ciw<CTRL-r>a<ESC>`{normal}
31+
32+
**MNEMONIC**: *(c)hange (i)nner (w)ord with <contents of (r)egister> named (a)*
33+
34+
5. Navigate to any point on the word 'cake' and type `ciw<CTRL-r>b<ESC>`{normal}
35+
36+
a) Edward will henceforth be in charge of the cookie rations
37+
b) In this capacity, Vince will have sole cake discretionary powers
38+
39+
NOTE: Delete also works into registers, i.e. `"sdiw`{normal} will delete
40+
the word under the cursor into register s.
41+
42+
REFERENCE: [Registers](registers)
43+
[Named Registers](quotea)
44+
[Motion](text-objects)
45+
[CTRL-R](i_CTRL-R)
46+
47+
48+
# Lesson 2.1.2: THE EXPRESSION REGISTER
49+
50+
** Insert the results of calculations on the fly **
51+
52+
1. Move the cursor to the line below marked ✗
53+
54+
2. Navigate to any point on the supplied number
55+
56+
3. Type `ciw<CTRL-r>=`{normal}60\*60\*24 `<ENTER>`{normal}
57+
58+
4. On the next line, enter insert mode and add today's date with
59+
`<CTRL-r>=`{normal}`system('date')`{vim} `<ENTER>`{normal}
60+
61+
NOTE: All calls to system are OS dependent, e.g. on Windows use
62+
`system('date /t')`{vim} or `:r!date /t`{vim}
63+
64+
I have forgotten the exact number of seconds in a day, is it 84600?
65+
Today's date is:
66+
67+
NOTE: the same can be achieved with `:pu=`{normal}`system('date')`{vim}
68+
or, with fewer keystrokes `:r!date`{vim}
69+
70+
REFERENCE: [Expression Register](quote=)
71+
72+
73+
# Lesson 2.1.3: THE NUMBERED REGISTERS
74+
75+
** Press `yy`{normal} and `dd`{normal} to witness their effect on the registers **
76+
77+
1. Move the cursor to the line below marked ✓
78+
79+
2. yank the zeroth line, then inspect registers with `:reg`{vim} `<ENTER>`{normal}
80+
81+
3. delete line 0. with `"cdd`{normal}, then inspect registers
82+
(Where do you expect line 0 to be?)
83+
84+
4. continue deleting each successive line, inspecting `:reg`{vim} as you go
85+
86+
NOTE: You should notice that old full-line deletions move down the list
87+
as new full-line deletions are added
88+
89+
5. Now (p)aste the following registers in order; c, 7, 4, 8, 2. i.e. `"7p`{normal}
90+
91+
0. This
92+
9. wobble
93+
8. secret
94+
7. is
95+
6. on
96+
5. axis
97+
4. a
98+
3. war
99+
2. message
100+
1. tribute
101+
102+
103+
NOTE: Whole line deletions (`dd`{normal}) are much longer lived in the
104+
numbered registers than whole line yanks, or deletions involving
105+
smaller movements
106+
107+
REFERENCE: [Numbered Registers](quote0)
108+
109+
110+
# Lesson 2.1.4: THE BEAUTY OF MARKS
111+
112+
** Code monkey arithmetic avoidance **
113+
114+
NOTE: a common conundrum when coding is moving around large chunks of code.
115+
The following technique helps avoid number line calculations associated
116+
with operations like `"a147d`{normal} or `:945,1091d a`{vim} or even worse
117+
using `i<CTRL-r>=`{normal}1091-945 `<ENTER>`{normal} first
118+
119+
1. Move the cursor to the line below marked ✓
120+
121+
2. Go to the first line of the function and mark it with `ma`{normal}
122+
123+
NOTE: exact position on line is NOT important!
124+
125+
3. Navigate to the end of the line and then the end of the code block
126+
with `$%`{normal}
127+
128+
4. Delete the block into register a with `"ad'a`{normal}
129+
130+
**MNEMONIC**: *into register(") named (a) put the (d)eletion from the cursor to
131+
the LINE containing mark(') (a)*
132+
133+
5. Paste the block between BBB and CCC `"ap`{normal}
134+
135+
NOTE: practice this operation multiple times to become fluent `ma$%"ad'a`{normal}
136+
137+
~~~ cmd
138+
AAA
139+
function itGotRealBigRealFast() {
140+
if ( somethingIsTrue ) {
141+
doIt()
142+
}
143+
// the taxonomy of our function has changed and it
144+
// no longer makes alphabetical sense in its current position
145+
146+
// imagine hundreds of lines of code
147+
148+
// naively you could navigate to the start and end and record or
149+
// remember each line number
150+
}
151+
BBB
152+
CCC
153+
~~~
154+
155+
NOTE: marks and registers do not share a namespace, therefore register a is
156+
completely independent of mark a. This is not true of registers and
157+
macros.
158+
159+
REFERENCE: [Marks](marks)
160+
[Mark Motions](mark-motions) (difference between ' and \`)
161+
162+
163+
# Lesson 2.1 SUMMARY
164+
165+
1. To store (yank, delete) text into, and retrieve (paste) from, a total of
166+
26 registers (a-z)
167+
2. Yank a whole word from anywhere within a word: `yiw`{normal}
168+
3. Change a whole word from anywhere within a word: `ciw`{normal}
169+
4. Insert text directly from registers in insert mode: `<CTRL-r>a`{normal}
170+
171+
5. Insert the results of simple arithmetic operations:
172+
`<CTRL-r>=`{normal}60\*60 `<ENTER>`{normal} in insert mode
173+
6. Insert the results of system calls:
174+
`<CTRL-r>=`{normal}`system('ls -1')`{vim} in insert mode
175+
176+
7. Inspect registers with `:reg`{vim}
177+
8. Learn the final destination of whole line deletions: `dd`{normal} in
178+
the numbered registers, i.e. descending from register 1 - 9. Appreciate
179+
that whole line deletions are preserved in the numbered registers longer
180+
than any other operation
181+
9. Learn the final destination of all yanks in the numbered registers and
182+
how ephemeral they are
183+
184+
10. Place marks from command mode `m[a-zA-Z0-9]`{normal}
185+
11. Move line-wise to a mark with `'`{normal}
186+
187+
188+
# CONCLUSION
189+
190+
This concludes chapter two of the Vim Tutor. It is a work in progress.
191+
192+
This chapter was written by Paul D. Parker.
193+
194+
Modified for vim-tutor-mode by Restorer.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"expect": {
3+
"36": -1,
4+
"37": "b) In this capacity, Edward will have sole cookie discretionary powers",
5+
"64": "I have forgotten the exact number of seconds in a day, is it 86400",
6+
"65": -1,
7+
"91": -1,
8+
"138": -1
9+
}
10+
}

0 commit comments

Comments
 (0)