How can I customize comment block characters in Visual Studio Code?

OK, I finally figured out what the problem was.
There are two ways you can change the comment blocks:

1. Configuration file

I don’t know why it’s not in the documentation (or at least I couldn’t find it), but there is an optional property you pass to the object inside the contributes.languages array in the package.json file named configuration.

The description found on the Visual Studio Code source code:

A relative path to a file containing configuration options for the
language.

In those files you can create an object like this one and it’s going to overwrite the default comment characters

{
  "comments": {
    "lineComment": "//",
    "blockComment": [ "<!--", "-->" ]
  }
}

You can see this properties on the API references: CommentRule

Note: That comment block command is triggered with a different shortcut. You can overwrite it though (in a general or even for a specific language using the property when on the key binding object).

⇧⌥A – Toggle Block Comment – editor.action.blockComment

Key Bindings for Visual Studio Code

2. “Syntax” file .tmLanguage

Yes, you can do it from there too and you can make it even better.
You can see an example on vscode-handlebars/syntaxes/handlebars.tmLanguage.

Leave a Comment