In this post, we will learn how to do single line and block (multi-line) comments 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 used for writing configuration files. Its extensions are .yaml
or .yml
.
YAML also let us comment on the instruction in the configuration files. Here in this post, we will see two ways 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 a comment in the YAML language.
Example
# This is a YAML comment
Block (Multiline) Comment in YAML file
YAML does not support block comment. However, we can do block comments or multi-line comments in the YAML file using keyboard shortcuts.
To write a block comment in the YAML file using shortcuts follow the steps below:
Step 1: First select the block of line that you want to comment on.
Step 2: Press Ctrl + /
on windows and Linux or cmd + /
on MacOS.
This will comment on the whole block of text in the file.
Note: This keyboard shortcut method works only on the following editors:
- Visual Studio Code
- Sublime Text Editor
- Atom Editor
- JetBrains IDE
- Eclipse
That’s how you can comment single line or multiple lines in a YAML file.