YAML comments

Comments are used to describe meaningful message about line of code.

Usually in any technology, There are two types of comments

  • Inline or single line comments
  • Block level comments

YAML has the syntax support for inline comments , but not for block level comments

Inline comments in yaml

Inline comments are comments declared at the line of code Hashtag symbol is used at the start of the line to tell processor that it is comment

Here is an code for yaml inline comments example

#  comments Syntax example in YAML file

#### comments example

These only specifies as single line comments. Each line of comment starts with hashtag(#) symbol and blank space followed by description. Each line will end with new line break.

Block level comments in yaml

Block comments are to comment the multiple lines . YAML has no support for block comments by default, You can use multiple inline comments

# block level comment example
# comment line 1
# comment line 2
# comment line 3

Important notes of comments in YAML

Comments are ignored by YAML processor It useful to document about the line of code, enables developers life is easy to understand Support short cut commands by different IDE

Comment and uncomment in Editor

Let’s see how do we comment or uncomment in different popular editors There are short cut keys used to comment in popular editors

Comment in eclipse

Eclipse by default has no support for YAML, First install YEdit plugin from Eclipse marketplace

YEdit is editor for YAML , to support Edit,Syntax highlight, Checking and content highlight with multiple colors.

Select the line which you want to comment code

Please issue a shortcut command CTRL + Shift + C to comment the code

To uncomment the code, Please select and issue the same shortcut command again to revert the comments. The other way is using menu or context menu option

Select the line of code Right click and select toggle comments

Comment and uncomment in Visual Studio code

VSCode by default has support for YAML editor features.

Please select the line or multiple lines of code which you want to comment

and issue a shortcut command CTRL + / to comment the text

Please issue again same command to uncomment the text

How to comment in ATOM editor

In Atom editor, you can select the multiple lines issue following commands to comment

  • ctrl + / in windows and linux
  • cmd + / in mac OS