Commenting Code Cheatsheet

This is a note to myself about how to put comments in the code that I mainly work with.

comment type
Language(s)
Comment Syntax     Notes

inline[1]
AsciiDoc

// comment

removed by Asciidoctor in HTML output

block[2]
AsciiDoc

////
comment
////

 

removed by Asciidoctor in HTML output

inline
bash script, PowerShell, Python, R, robots.txt, TOML, nix-nux shell script, YAML (and a lot more)

# comment

block
bash script

: <<'EndComment'
comment
EndComment

 

the string EndComment can be anything;⁠[3] this is called a “here document” or “heredoc”

inline
BAT and CMD

@rem comment

“rem” is case insensitive; it means remark

block
BAT and CMD

GOTO EndRemark
comment
:EndRemark

 

the string EndRemark can be anything;⁠[3] this is discussed in stackoverflow.com’s Commenting multiple lines in DOS batch file

inline or block
Go Template

{{/* comment */}}

or…

{{- /* comment */ -}}
 

removed by Hugo in HTML output; examples in Infinite Ink’s Hugo Tips, Shortcodes, and Fragments

inline or block
HTML and Markdown

<!-- comment -->

inline
JSON

// comment

allowed only sometimes, e.g. in Visual Studio Code’s settings.json. See stackoverflow.com’s Can comments be used in JSON?

inline or block
PowerShell

<# comment #>

requires PowerShell 2.0[4] or later

inline or block
SCSS and CSS

/* comment */

not removed by SASS in CSS output

inline or block
SCSS

/*! comment */

not removed by SASS in CSS output

inline
SCSS

// comment

removed by SASS in CSS output

inline
vimrc

" comment

block
YAML

commenthack: >
  multi-line
  comment

 

this is a hack that is discussed in stackoverflow.com’s How do you do block comments in YAML? Also see yaml-multiline.info.

 

References

Endnotes


1. An inline comment is also known as a single-line comment.
2. A block comment is also known as a multi-line comment.
3. Actually, any string without special characters.
4. PowerShell 2.0 was released in 2009 (~11 years ago). To see if you are using PowerShell 2.0 or higher, run $psversiontable, $psversiontable.psversion, or $psversiontable.psversion.major at a PowerShell prompt.

Edit this page👍👎📝

To add a reaction emoji or a comment to this page, you need a GitHub account.