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, TOML, nix-nux shell, YAML (and a lot more languages)

# 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” 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 Fragments and Tips

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?

 

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 find out your PowerShell version, run $PSVersionTable.PSVersion at a PowerShell prompt.

Edit this page👍👎✍

To add a reaction or comment to this page, you need a GitHub account and your browser needs to be able to run a script that is hosted at https://utteranc.es.