Inline And Block Comment in YAML File


In this post we will learn how to do single line and block (multi-line) comment in a YAML File.

A YAML (yet another markup language) is a programming language which is known as the human-readable data-serialization language. It is a powerful language that is use for writing configuration files. Its extensions are .yaml or .yml.

YAML also let us to comment the instruction in the configuration files. Here in this post we will see two ways on how to comment on a YAML config file.

Inline (Single-line) Comment in YAML File

The common way to do an inline comment in a YAML file is to use the # (hashtag) symbol at the start of the line.

So, anything written after the # (hashtag) symbol till the end of the line will be considered as comment in YAML language.

Example

# This is a YAML comment

Block (Multiline) Comment in YAML file

YAML do not support block comment . However we can do block comment or multi-line comment in YAML file using keyboard shortcuts.

To write block comment in YAML file using shortcuts follow the steps below:

Step 1: First select the block of line that you want to comment.

 multi line comment in yaml

Step 2: Press Ctrl + /on windows and Linux or cmd + /on MacOS.

how to multi line comment in yaml

This will comment the whole block of text in the file.

Note: This keyboard shortcut method works only on the following editors:

  1. Visual Studio Code
  2. Sublime Text Editor
  3. Atom Editor
  4. JetBrains IDE
  5. Eclipse

That's how you can comment single line or multiple lines in a YAML file.

Related Topics:

Single-Line And Multi-Line Comment | Javascript Comment


💾 Recommended Articles