I am coding in VS Code. You can press ‘Shift + Alt + A’ to make block comments. If I have the lines of code:
console.log("...");
console.log("...");
console.log("...");
and press the block comment keyboard shortcut, they show up like this:
/* console.log("...");
console.log("...");
console.log("..."); */
However, I want them to be formatted with a newline after and before the beginning and end of the text portion of the block comment like this:
/*
console.log("...");
console.log("...");
console.log("...");
*/
Is there any setting you know of to format the comments this way?
I have been looking for settings and searching on other forums to find ways to do this, but it must be either an uncommon question, or I am wording it incorrectly.
2
Answers
As far as I can tell from reading https://github.com/microsoft/vscode/issues/48074, this should already be supported by putting newline characters in the delimiter definitions in the language configuration (but (at the time of this writing) has issues with removing the code block using the same keyboard shortcut).
I’m not aware of a way to do it aside from it being configured at the language-extension level. I’m not aware of there being a feature-request issue ticket tracking doing it at a user-configuration (settings) level. You could create one. If you do, please comment here with a link to your issue ticket, or edit the link into this answer post.
Unfortunately as mentioned there is a bug in vscode which prevents this from easily being customized.
Here is a workaround using an extension I wrote,
Find and Transform. It allows you run vscode api’s in a keybinding (or setting) Make this keybinding (in your
keybindings.json
):Alternatively, you can try another extension I wrote, Custom Language Properties. With it, you could make a setting like this (assuming javascript in this case – but it works for other languages too.
You see I just added newlines after and before the block comment characters.
And that works perfectly to add block comments as you want to a selection. But due to the vscode bug it won’t toggle the comments off properly.
You could either live with manually deleting the comment characters yourself or use the keybinding shown above.