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
|
# CREATING A VIM TUTORIAL WITH VIM-TUTOR-MODE
This tutorial will guide you through the steps required to create a tutorial
file for vim-tutor-mode. It is also meant as a demo of vim-tutor-mode
capabilities.
Table of contents:
- [Setting up](*setting-up*)
- [vim-tutor-mode's markup](*markup*)
- [emphasis](*emphasis*)
- [headers](*headers*)
- [links](*links*)
- [codeblocks](*codeblocks*)
- [Interactive elements](*interactive*)
- [expect](*expect*)
## SETTING UP *setting-up*
First, you'll need to enable "debug" mode
~~~ cmd
:let g:tutor_debug = 1
~~~
This will allow saving changes to the tutor files and will disable conceals, so
you can more easily check your changes.
After this, create a new .tutor file (we will be practicing on this very file, so you
don't need to do this now):
~~~ cmd
:e new-tutorial.tutor
~~~
## VIM-TUTOR-MODE's MARKDOWN *markup*
vim-tutor-mode uses a subset of markdown's syntax to format the tutorials. The
subset supported should be enough for most tutorials and the maintainers will
try to keep it as small as possible (if regular markdown allows for several
ways to do the same thing, tutor markdown will only provide the one the
maintainers think is easier to handle).
### Emphasis *emphasis*
For emphasized text (italics), as in normal markdown, you use \*. E.g.:
\*text\*
is displayed like
*text*
Note: The underscores variant is not supported.
For strong emphasis (bold), you use \*\*. E.g.:
\*\*this\*\*
is displayed like
**this**
1. Format the line below so it becomes a lesson description:
---> This is text with important information {expect:This is text with **important information**}
---> This is text with **important information** {expect:This is text with **important information**}
Note: Some words (e.g., NOTE, IMPORTANT, tip, ATTENTION, etc.) will also be
highlighted. You don't need to mark them specially.
2. Turn the line below into a TODO item:
---> Document '&variable' {expect:TODO: Document '&variable'}
---> TODO: Document '&variable' {expect:TODO: Document '&variable'}
### Headers *headers*
3. Practice fixing the lines below:
---> This is a level 1 header {expect:# This is a level 1 header}
---> # This is a level 1 header {expect:# This is a level 1 header}
---> This is a level 3 header {expect:### This is a level 3 header}
---> ### This is a level 3 header {expect:### This is a level 3 header}
---> This is a header with a label {expect:# This is a header with a label {*label*}}
---> # This is a header with a label {*label*} {expect:# This is a header with a label {*label*}}
4. Now, create a 4th level section here, and add a label like in the previous
exercise:
ATTENTION We will use this label later, so remember it.
### Links *links*
It is good practice to include links in your tutorials to reference materials,
like vim's own help or external documents. You can also link to other parts of
the document.
Links have the syntax
\[label\]\(target\)
#### Help links
If the target of a link matches a help topic, opening it will open it.
5. Fix the following line:
---> A link to help for the 'breakindent' option {expect:A link to help for the ['breakindent']('breakindent') option}
---> A link to help for the ['breakindent']('breakindent') option {expect:A link to help for the ['breakindent']('breakindent') option}
#### Anchor links
A link can also lead to a place in the file itself. Anchors are written
\*anchor\*
and are hidden by default. Links to them look like
\[label\]\(\*anchor\*\)
6. Add the appropiate link:
---> A link to the Links section {expect:A link to the [Links](*links*) section}
---> A link to the [Links](*links*) section {expect:A link to the [Links](*links*) section}
7. Now, create a link to the section you created on exercise 4
above.
# Tutorial links
You can also have links to other tutorials. For this, you'll write the anchor in the format
@tutor:TUTORIAL
7. Create a link to this tutorial:
---> A link to the vim-tutor-mode tutorial {expect:A link to [the vim-tutor-mode tutorial](@tutor:tutor)}
---> A link to [the vim-tutor-mode tutorial](@tutor:tutor) {expect:A link to [the vim-tutor-mode tutorial](@tutor:tutor)}
### Codeblocks *codeblocks*
vim-tutor-mode tutorials can include viml sections
~~~ cmd
echom "hello"
~~~
is displayed as
~~~ cmd
echom "hello"
~~~
8. Copy the viml section below
---> {expect:~~~ viml}
---> {expect:echom "the value of &number is".string(&number)}
---> {expect:~~~}
---> ~~~ viml {expect:~~~ viml}
---> echom "the value of &number is".string(&number) {expect:echom "the value of &number is".string(&number)}
---> ~~~ {expect:~~~}
You can inline viml code using "\`" and "\`{vim}":
\`call myFunction()\`{vim}
is displayed as
`call myFunction()`{vim}
[normal](Normal-mode) commands can also be embedded in tutorials.
~~~ normal
ftdaW
~~~
is displayed as
~~~ normal
ftdaW
~~~
Note: you can also write `norm` or `normal`.
9. Copy the normal section below
---> {expect:~~~ normal}
---> {expect:d2w}
---> {expect:~~~}
---> ~~~ normal {expect:~~~ normal}
---> d2w {expect:d2w}
---> ~~~ {expect:~~~}
You can also inline normal commands by using "\`" and "\`{normal}":
\`gq\`{normal} is very useful.
is displayed:
`gq`{normal} is very useful.
10. Complete the line as shown
---> d {expect:«d2w»}
---> «d2w» {expect:«d2w»}
Commands to run in the system shell can be highlighted by indenting a line starting with "$".
~~~ sh
$ vim --version
~~~
## INTERACTIVE ELEMENTS *interactive*
As visible in this very document, vim-tutor-mode includes some interactive
elements, to provide feedback to the user about his progress. These elements
all have the syntax
\---> TEXT {CLAUSE}
where \---> must start at the beginning of the line. If TEXT satisfies CLAUSE,
a ✓ sign will appear to the left. A ✗ sign is displayed otherwise. The CLAUSE
itself is hidden unless debug mode is set or ['conceallevel']('conceallevel')
is 2.
### expect *expect*
The basic clause is "expect", which is satisfied if TEXT is the same as the
content of the clause. For example
\---> TEXT {expect:TEXT}
is satisfied, but
\---> OTHER TEXT {expect:TEXT}
is not.
13. Make both lines the same:
---> this is not right {expect:---> this is right} |expect:---> this is right {expect:---> this is right}|
---> ---> this is right {expect:---> this is right} |expect:---> this is right {expect:---> this is right}|
If the content of a expect clause is ANYTHING, no checks will be performed. This is
useful to create a line that is highlighted you want the user to play with.
\---> TEXT {expect:ANYTHING}
is displayed
---> this is free text {expect:ANYTHING}
14. Turn the line below into free text:
---> this is some text |expect:---> this is some text {expect:ANYTHING}|
---> ---> this is some text {expect:ANYTHING} |expect:---> this is some text {expect:ANYTHING}|
|