YAML Comments

YAML Comments

Comments can be included on the YAML body you are composing. Here are some ways to add comments.

Every comment has to be started by a hashtag (#) like the following example.

# This is a comment example

YAML does not support block level comments. So, if you want to add multiple lines of comment, add a hashtag on every line (before the comment you want to type).

# This is an example
# of a multiple line
# comment

In the YAML collection, comments will be displayed like the example below.

Key: # comment_a
 - Value line a
# comment_b
 - Value line b

Note that comments in YAML conform to these characteristics.

  • They are not in the block comments form. The comments cannot escape from the #’s influence. Even in the form of multiple comments, there is no way to divide them in raw string value.
  • Help the users to add some descriptions to the code block. Therefore they can compose the codes more specifically. Take a look at this example.
--- # lecturers, by working period
Seniors: [Margy, Wet]
Juniors: [Akubaru, Parumin] 
  • Comments must not appear inside the scalars.

The comment addition can also be finished through the shortcut. The shortcut itself depends on what software you use.

Comment in Eclipse

The default version of Eclipse does not support YAML, but you can install the YEdit from the Eclipse marketplace to begin. You can select which line you want to add as a comment, then press Ctrl+Shift+C. You can also undo the commenting through the same steps. The other way is by the menu usage. You can block the line you want to add as a comment, then right-click, and select the toggle comments. 

Comment in Visual Studio Code

Select the line or multiple lines you want to add as comment(s), then click Ctrl+/. Rerun the step if you want to undo the comment.

Commenting with ATOM Editor

Select the line or multiple line, press Ctrl+/ for Windows and Linux OS, or Cmd+/ for Mac iOS

Comment in Sublime Text Editor 

Shortcut for commenting in the Sublime Text Editor is similar to the ATOM Editor previously mentioned. You can select the line or multiple lines you want to add as comment(s), press Ctrl+/ for Windows and Linux OS, or Cmd+/ for Mac iOS.   

Check out YAML Language Features for more helpful information.

%d bloggers like this: