'how to make a custom comment style in vscode

I got a source code commented like below.

// //------------------------------------------------------------------------------
// //======================= Variable Declaration =================================

Is there any way to make a comment like the above in vs code.

I only got single and multiline comments.

But I want the above custom style.



Solution 1:[1]

You can make a snippet to do that. In one of your snippets files:

"Variable Declaration Comment": {
    "prefix": "_gc",          // whatever trigger you want
    "body": [
      "$LINE_COMMENT $LINE_COMMENT------------------------------------------------------------------------------",
      "$LINE_COMMENT $LINE_COMMENT======================= ${TM_SELECTED_TEXT} =================================$0",
    ],
    "description": "Insert a Variable Declaration comment header"
}

That will use whatever the line comment style is for the type of file you are in: $LINE_COMMENT.

You could set that to a keybinding like this (in your keybindings.json file):

{
  "key": "alt+q",    // whatever keybinding you want 
  "command": "editor.action.insertSnippet",
  "args": {
    "name": "Variable Declaration Comment"
  },
  "when": "editorTextFocus"
}

Solution 2:[2]

You can use the extension HyperSnips

Define the following snippet in the all.hsnips file

snippet comment "Comment Section"
// //------------------------------------------------------------------------------
// //``s = '='.repeat((78-(t[0].length + 2))/2); rv = s;`` $1 ``rv = '='.repeat(78-(t[0].length + 2 + s.length));``
endsnippet

If you type comment and select the snippet with Tab you can type the text and the === strings adjust to keep the text centered.

You can also cut some text - start the snippet - and paste the text.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 rioV8