How to block comments in YAML ?

YAML is a human-friendly data serialization standard for all programming languages. It is commonly used for configuration files and in applications where data is being stored or transmitted.

The Normal Way for commenting in YAML is Inline commenting with the “#” symbol, however, if you want to comment blocks then we have a list of ways in which it can be done.

Step 1: Select the block

Step 2: Press cmd plus / on Mac or press ctrl plus / on Linux & Windows.

Note: This method works on the following editors –

  • Sublime Text Editor
  • Atom Editor
  • Eclipse (with YEdit plugin)
  • JetBrains IDEs: RubyMine and Gogland
  • Visual Studio Code

At any level of the code, you may add a new block text named like “Description” or “Comment” or “Notes” or whatever that you wish

Example:

Instead of
# This comment
# is too long

use
Description: >
This comment
is too long

or
Comment: >
This comment is also too long
and newlines survive from parsing!

Advantages:

  • If the comments become too large and too complex and have a lot of repeating pattern, you may want to promote them from plain text blocks to objects.
  • Your app may need to read/update the comments in the future.
  • This method is very handy especially if anyone wants these comments to appear in JSON or XML if one is to transform from YAML to these two.
My Personal Notes arrow_drop_up

Machine Learning ,Front-End Web Development

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.