您可以设置一个宏来非常轻松地完成此操作。
首先,使用优秀的选择依据 https://marketplace.visualstudio.com/items?itemName=rioj7.select-by扩展名 (@rioV8),用于选择块注释标记之间(包括块注释标记)的文本/*
and */
。将其放入您的设置中:
"selectby.regexes": {
"BlockCommentSelect": {
"backward": "\/\\*",
"forward": "\\*\/",
"forwardInclude": true,
"backwardInclude": true,
"showSelection": true
}
},
您可以将其与键绑定一起使用,例如:
{
"key": "alt+s", // whatever keybinding you wish
"command": "selectby.regex",
"args": ["BlockCommentSelect"],
"when": "editorTextFocus"
},
You could stop here and use your keybinding to select the text and then Shift+Alt+A to toggle off the block comment.
或者你可以添加selectby.regex1
到宏并一步完成选择和切换。这里使用宏扩展多命令 https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command将其放入您的设置以及上面的设置中selectby.regexes
环境:
"multiCommand.commands": [
{
"command": "multiCommand.BlockCommentOff",
"sequence": [
{
"command": "selectby.regex",
"args": ["BlockCommentSelect"]
},
"editor.action.blockComment"
]
},
]
然后是一个键绑定来触发该宏(在您的 keybindings.json 中):
{
"key": "shift+alt+A", // trigger the macro with whatever keybinding if you wish
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.BlockCommentOff" },
"when": "editorTextFocus && !editorHasSelection"
},
Here I used Shift+Alt+A to trigger the macro. And I used the when
clause !editorHasSelection
because if you have a selection maybe you want to block comment only that selection (inside another block comment!!).
演示:(1) 只是第一种方法selectby
选择您的文本并手动将其关闭,然后 (2) 使用宏版本一步完成此操作。