Using VSCode snippets, I would like to have the following behaviour. Say I select the word "foobarbaz", then (using a snippet) I would like it to turn into
/******************************************************************************/
/* foobarbaz */
/******************************************************************************/
where the length of the comment block is fixed. This means that the number of spaces before and after "foobarbaz" depends on the length of "foobarbaz" itself. The idea is that the number of spaces on the left and on the right of the selected word is the same. In the cases where the length of the word is an odd number, I would have the left number of spaces to be one less than the right number of spaces.
Would it be possible to have this behviour implemented with VSCode snippets, or is it too complex?
2
Answers
there is an extension in vscode called Comment Bars that does the trick. with your arbitrary filler character.
Using an extension I wrote, Comment Blocks, this is quite easy.
Either this setting (in your
settings.json
):and a keybinding to trigger it (in your
keybindings.json
):Or just a keybinding:
will do this:
The extension can do a lot more customization, it just happens that your example is pretty simple and uses some of the defaults set by the extension, like
"justify": "center"
.Options are: