robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
dbdd73e846
master
1# CREATING A VIM TUTORIAL WITH VIM-TUTOR-MODE 2 3This tutorial will guide you through the steps required to create a tutorial 4file for vim-tutor-mode. It is also meant as a demo of vim-tutor-mode 5capabilities. 6 7Table of contents: 8 9- [Setting up](*setting-up*) 10- [vim-tutor-mode's markup](*markup*) 11 - [emphasis](*emphasis*) 12 - [headers](*headers*) 13 - [links](*links*) 14 - [codeblocks](*codeblocks*) 15- [Interactive elements](*interactive*) 16 - [expect](*expect*) 17 18## SETTING UP *setting-up* 19 20Create a new .tutor file (we will be practicing on this very file, so you don't 21need to do this now): 22~~~ cmd 23 :e new-tutorial.tutor 24~~~ 25 26## VIM-TUTOR-MODE's MARKDOWN *markup* 27 28vim-tutor-mode uses a subset of markdown's syntax to format the tutorials. The 29subset supported should be enough for most tutorials and the maintainers will 30try to keep it as small as possible (if regular markdown allows for several 31ways to do the same thing, tutor markdown will only provide the one the 32maintainers think is easier to handle). 33 34### Emphasis *emphasis* 35 36For emphasized text (italics), as in normal markdown, you use \*. E.g.: 37 38 \*text\* 39 40is displayed like 41 42 *text* 43 44Note: The underscores variant is not supported. 45 46For strong emphasis (bold), you use \*\*. E.g.: 47 48 \*\*this\*\* 49 50is displayed like 51 52 **this** 53 541. Format the line below so it becomes a lesson description: 55 56This is text with important information [[This is text with **important information**]] 57This is text with **important information** [[This is text with **important information**]] 58 59Note: Some words (e.g., NOTE, IMPORTANT, tip, ATTENTION, etc.) will also be 60highlighted. You don't need to mark them specially. 61 622. Turn the line below into a TODO item: 63 64Document '&variable' [[TODO: Document '&variable']] 65TODO: Document '&variable' [[TODO: Document '&variable']] 66 67### Headers *headers* 68 693. Practice fixing the lines below: 70 71This is a level 1 header [[# This is a level 1 header]] 72# This is a level 1 header [[# This is a level 1 header]] 73This is a level 3 header [[### This is a level 3 header]] 74### This is a level 3 header [[### This is a level 3 header]] 75This is a header with a label [[# This is a header with a label {*label*}]] 76# This is a header with a label {*label*} [[# This is a header with a label {*label*}]] 77 784. Now, create a 4th level section here, and add a label like in the previous 79exercise: 80 81 82 83 ATTENTION We will use this label later, so remember it. 84 85### Links *links* 86 87It is good practice to include links in your tutorials to reference materials, 88like vim's own help or external documents. You can also link to other parts of 89the document. 90 91Links have the syntax 92 93 \[label\]\(target\) 94 95#### Help links 96 97If the target of a link matches a help topic, opening it will open it. 98 995. Fix the following line: 100 101A link to help for the 'breakindent' option [[A link to help for the ['breakindent']('breakindent') option]] 102A link to help for the ['breakindent']('breakindent') option [[A link to help for the ['breakindent']('breakindent') option]] 103 104#### Anchor links 105 106A link can also lead to a place in the file itself. Anchors are written 107 108 \*anchor\* 109 110and are hidden by default. Links to them look like 111 112 \[label\]\(\*anchor\*\) 113 1146. Add the appropriate link: 115 116A link to the Links section [[A link to the [Links](*links*) section]] 117A link to the [Links](*links*) section [[A link to the [Links](*links*) section]] 118 1197. Now, create a link to the section you created on exercise 4 120 above. 121 122 123 124# Tutorial links 125 126You can also have links to other tutorials. For this, you'll write the anchor in the format 127 128 @tutor:TUTORIAL 129 1307. Create a link to this tutorial: 131 132A link to the vim-tutor-mode tutorial [[A link to [the vim-tutor-mode tutorial](@tutor:tutor)]] 133A link to [the vim-tutor-mode tutorial](@tutor:tutor) [[A link to [the vim-tutor-mode tutorial](@tutor:tutor)]] 134 135### Codeblocks *codeblocks* 136 137vim-tutor-mode tutorials can include viml sections 138 139 ~~~ cmd 140 echom "hello" 141 ~~~ 142 143is displayed as 144~~~ cmd 145echom "hello" 146~~~ 147 1488. Copy the viml section below 149 150 [[~~~ viml]] 151 [[echom 'the value of &number is'.string(&number)]] 152 [[~~~]] 153 154~~~ viml [[~~~ viml]] 155echom 'the value of &number is'.string(&number) [[echom 'the value of &number is'.string(&number)]] 156~~~ [[~~~]] 157 158You can inline viml code using "\`" and "\`{vim}": 159 160 \`call myFunction()\`{vim} 161 162is displayed as 163 164 `call myFunction()`{vim} 165 166[normal](Normal-mode) commands can also be embedded in tutorials. 167 168 ~~~ normal 169 ftdaW 170 ~~~ 171 172is displayed as 173~~~ normal 174ftdaW 175~~~ 176 177Note: you can also write `norm` or `normal`. 178 1799. Copy the normal section below 180 181 [[~~~ normal]] 182 [[d2w]] 183 [[~~~]] 184 185~~~ normal [[~~~ normal]] 186d2w [[d2w]] 187~~~ [[~~~]] 188 189You can also inline normal commands by using "\`" and "\`{normal}": 190 191 \`gq\`{normal} is very useful. 192 193is displayed: 194 195 `gq`{normal} is very useful. 196 19710. Complete the line as shown 198 199d [[`d2w`{normal}]] 200`d2w`{normal} [[`d2w`{normal}]] 201 202Commands to run in the system shell can be highlighted by indenting a line 203starting with "$". 204 205~~~ sh 206 $ vim --version 207~~~ 208 209## INTERACTIVE ELEMENTS *interactive* 210 211As visible in this very document, vim-tutor-mode includes some interactive 212elements to provide feedback to the user about their progress. If the text in 213these elements satisfies some set condition, a ✓ sign will appear in the gutter 214to the left. Otherwise, a ✗ sign is displayed. 215 216### expect *expect* 217 218"expect" lines check that the contents of the line are identical to some preset text 219(like in the exercises above). The expected text is defined in inline comments that 220are not visible to the user. 221 222An example line is written like "This is wrong. [[This is right.]]" 223The user will see "This is wrong." and have an interactive sign. 224 225A value of [[-1]] means that the condition for the line will always be satisfied, 226no matter what (this is useful for letting the user play a bit). 227 228This is an "expect" line that is always satisfied. Try changing it. [[-1]] 229 230For a full example, see the file that corresponds to this tutorial.