YAML - Comments
Now that you are comfortable with the syntax and basics of YAML, let us proceed further into its details. In this chapter, we will see how to use comments in YAML.
YAML supports single line comments. Its structure is explained below with the help of an example −
# this is single line comment.
YAML does not support multi line comments. If you want to provide comments for multiple lines, you can do so as shown in the example below −
# this # is a multiple # line comment
Features of Comments
The features of comments in YAML are given below −
A commented block is skipped during execution.
Comments help to add description for specified code block.
Comments must not appear inside scalars.
YAML does not include any way to escape the hash symbol (#) so within multi-line string so there is no way to divide the comment from the raw string value.
The comments within a collection are shown below −
key: #comment 1 - value line 1 #comment 2 - value line 2 #comment 3 - value line 3
The shortcut key combination for commenting YAML blocks is Ctrl+Q.
If you are using Sublime Text editor, the steps for commenting the block are mentioned below −
Select the block. Use “CTRL + /” on Linux and Windows and “CMD+/” for Mac operating system. Execute the block.
Note that the same steps are applicable if you are using Visual Studio Code Editor. It is always recommended to use Sublime Text Editor for creating YAML files as it supported by most operating systems and includes developer friendly shortcut keys.