Remark multiple lines in a Yaml, Terraform, a Json files or PowerShell.
Often, I and many other decoders, get into a situation where you want to test only part of your code, or you need to make a temporary change in your Yaml / Json files or in PowerShell scripts.
Remarking multiple lines in a Yaml, Terraform or a Json files
You can remark multiple lines in a Yaml, Terraform or a Json files, using the Visual Studio Code (VS Code) or the Azure DevOps editor.
Just open the file using VS Code in our example and act as the following:
- Mark the relevant lines you would like to remark.
- Press the keyboard shortcut:
Ctrl + /
(Windows/Linux) orCmd + /
(Mac).
This shortcut toggles the comment status of the selected rows, adding or removing the comment characters.
- As for a Json file, the comment character is
//
, so the selected rows will have//
added at the beginning of each line.
- Other option, is to manually mark only the first row with
/*
and*/
at the last row you would like to mark, as the following example:
In the example above, the lines between the /*
and */
are considered comments and will be ignored by the Json when executing the script. You can add as many lines as you need within the comment block.
Remarking multiple lines in a PowerShell file
Also in PowerShell, you can remark multiple lines, using the Visual Studio Code (VS Code) as the same method for remarking multiple lines in Yaml or Terraform, using the Ctrl + /
shortcut:
- In case you would like to remark multiple lines in PowerShell Integrated Scripting Environment (ISE), act as the following:
- Mark the relevant lines you would like to remark.
- Press the keyboard shortcut:
Ctrl + H
- Type
^
in Find what - Type
#
in Replace with - Check the Regular Expression check box
- Click on Replace All
After the change, the lines will be remarked:
- Other option, is to manually mark only the first row with
<#
and#>
at the last row you would like to mark, as the following example:
In the example above, the lines between <#
and #>
are considered comments and will be ignored by PowerShell when executing the script. You can add as many lines as you need within the comment block.
Conclusion
Remarking multiple lines for testing or debugging are very useful.
Using the tricks above, can make your scripting and coding life, much easier and efficient!