tutor.tutor 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. # CREATING A VIM TUTORIAL WITH VIM-TUTOR-MODE
  2. This tutorial will guide you through the steps required to create a tutorial
  3. file for vim-tutor-mode. It is also meant as a demo of vim-tutor-mode
  4. capabilities.
  5. Table of contents:
  6. - [Setting up](*setting-up*)
  7. - [vim-tutor-mode's markup](*markup*)
  8. - [emphasis](*emphasis*)
  9. - [headers](*headers*)
  10. - [links](*links*)
  11. - [codeblocks](*codeblocks*)
  12. - [Interactive elements](*interactive*)
  13. - [expect](*expect*)
  14. ## SETTING UP *setting-up*
  15. First, you'll need to enable "debug" mode
  16. ~~~ cmd
  17. :let g:tutor_debug = 1
  18. ~~~
  19. This will allow saving changes to the tutor files and will disable conceals, so
  20. you can more easily check your changes.
  21. After this, create a new .tutor file (we will be practicing on this very file, so you
  22. don't need to do this now):
  23. ~~~ cmd
  24. :e new-tutorial.tutor
  25. ~~~
  26. ## VIM-TUTOR-MODE's MARKDOWN *markup*
  27. vim-tutor-mode uses a subset of markdown's syntax to format the tutorials. The
  28. subset supported should be enough for most tutorials and the maintainers will
  29. try to keep it as small as possible (if regular markdown allows for several
  30. ways to do the same thing, tutor markdown will only provide the one the
  31. maintainers think is easier to handle).
  32. ### Emphasis *emphasis*
  33. For emphasized text (italics), as in normal markdown, you use \*. E.g.:
  34. \*text\*
  35. is displayed like
  36. *text*
  37. Note: The underscores variant is not supported.
  38. For strong emphasis (bold), you use \*\*. E.g.:
  39. \*\*this\*\*
  40. is displayed like
  41. **this**
  42. 1. Format the line below so it becomes a lesson description:
  43. This is text with important information
  44. This is text with **important information**
  45. Note: Some words (e.g., NOTE, IMPORTANT, tip, ATTENTION, etc.) will also be
  46. highlighted. You don't need to mark them specially.
  47. 2. Turn the line below into a TODO item:
  48. Document '&variable'
  49. TODO: Document '&variable'
  50. ### Headers *headers*
  51. 3. Practice fixing the lines below:
  52. This is a level 1 header
  53. # This is a level 1 header
  54. This is a level 3 header
  55. ### This is a level 3 header
  56. This is a header with a label
  57. # This is a header with a label {*label*}
  58. 4. Now, create a 4th level section here, and add a label like in the previous
  59. exercise:
  60. ATTENTION We will use this label later, so remember it.
  61. ### Links *links*
  62. It is good practice to include links in your tutorials to reference materials,
  63. like vim's own help or external documents. You can also link to other parts of
  64. the document.
  65. Links have the syntax
  66. \[label\]\(target\)
  67. #### Help links
  68. If the target of a link matches a help topic, opening it will open it.
  69. 5. Fix the following line:
  70. A link to help for the 'breakindent' option
  71. A link to help for the ['breakindent']('breakindent') option
  72. #### Anchor links
  73. A link can also lead to a place in the file itself. Anchors are written
  74. \*anchor\*
  75. and are hidden by default. Links to them look like
  76. \[label\]\(\*anchor\*\)
  77. 6. Add the appropriate link:
  78. A link to the Links section
  79. A link to the [Links](*links*) section
  80. 7. Now, create a link to the section you created on exercise 4
  81. above.
  82. # Tutorial links
  83. You can also have links to other tutorials. For this, you'll write the anchor in the format
  84. @tutor:TUTORIAL
  85. 7. Create a link to this tutorial:
  86. A link to the vim-tutor-mode tutorial
  87. A link to [the vim-tutor-mode tutorial](@tutor:tutor)
  88. ### Codeblocks *codeblocks*
  89. vim-tutor-mode tutorials can include viml sections
  90. ~~~ cmd
  91. echom "hello"
  92. ~~~
  93. is displayed as
  94. ~~~ cmd
  95. echom "hello"
  96. ~~~
  97. 8. Copy the viml section below
  98. ~~~ viml
  99. echom 'the value of &number is'.string(&number)
  100. ~~~
  101. You can inline viml code using "\`" and "\`{vim}":
  102. \`call myFunction()\`{vim}
  103. is displayed as
  104. `call myFunction()`{vim}
  105. [normal](Normal-mode) commands can also be embedded in tutorials.
  106. ~~~ normal
  107. ftdaW
  108. ~~~
  109. is displayed as
  110. ~~~ normal
  111. ftdaW
  112. ~~~
  113. Note: you can also write `norm` or `normal`.
  114. 9. Copy the normal section below
  115. ~~~ normal
  116. d2w
  117. ~~~
  118. You can also inline normal commands by using "\`" and "\`{normal}":
  119. \`gq\`{normal} is very useful.
  120. is displayed:
  121. `gq`{normal} is very useful.
  122. 10. Complete the line as shown
  123. d
  124. `d2w`{normal}
  125. Commands to run in the system shell can be highlighted by indenting a line
  126. starting with "$".
  127. ~~~ sh
  128. $ vim --version
  129. ~~~
  130. ## INTERACTIVE ELEMENTS *interactive*
  131. As visible in this very document, vim-tutor-mode includes some interactive
  132. elements to provide feedback to the user about their progress. If the text in
  133. these elements satisfies some set condition, a ✓ sign will appear in the gutter
  134. to the left. Otherwise, a ✗ sign is displayed.
  135. ### expect *expect*
  136. "expect" lines check that the contents of the line are identical to some preset text
  137. (like in the exercises above).
  138. These elements are specified in separate JSON files like this
  139. ~~~ json
  140. {
  141. "expect": {
  142. "1": "This is how this line should look.",
  143. "2": "This is how this line should look.",
  144. "3": -1
  145. }
  146. }
  147. ~~~
  148. These files contain an "expect" dictionary, for which the keys are line numbers and
  149. the values are the expected text. A value of -1 means that the condition for the line
  150. will always be satisfied, no matter what (this is useful for letting the user play a bit).
  151. This is an "expect" line that is always satisfied. Try changing it.
  152. These files conventionally have the same name as the tutorial document with the `.json`
  153. extension appended (for a full example, see the file that corresponds to this tutorial).