我知道有一个注释和取消注释代码块的快捷方式(SHIFT + ALT + A),但是有一种方法可以快速选择(甚至删除而不选择)块注释,而无需使用鼠标或键盘来选择并按Delete / Backspace按钮?例如:
/*
This is a large block of code with at least 50 lines of code!
:
:
*/
是否存在键盘快捷键,我可以在其中放置光标块注释中的任何位置,只需单击几次即可将其删除?谢谢!
您可以设置宏来轻松完成此操作。
首先,使用出色的Select By扩展名选择块注释标记/*
和*/
之间并包括其的文本。将他设置为您的设置:
"selectby.regexes": {
"regex1": {
"backward": "\/\\*",
"forward": "\\*\/",
"forwardInclude": true,
"backwardInclude": true,
"showSelection": true
}
},
您可以将其与诸如以下的键绑定一起使用:
{
"key": "alt+s", // whatever keybinding you wish
"command": "selectby.regex1", // you may warning squiggles under the command but it will still work
"when": "editorTextFocus",
},
您可以在此处停止并使用键盘绑定选择文本,然后按Shift + Alt + A来关闭块注释。
或者您可以将selectby.regex1
添加到宏中,然后一步一步地进行选择和切换。在这里,使用宏扩展名multi-command以及上面的selectby.regexes
设置将其设置为您的设置:
"multiCommand.commands": [
{
"command": "multiCommand.BlockCommentOff",
"sequence": [
"selectby.regex1", // run the selectby command defined above
"editor.action.blockComment" // toggle off the block comment
]
}
]
然后是用于触发该宏的键绑定(在您的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"
},
这里我用Shift + Alt + A触发宏。我使用了when
子句!editorHasSelection
,因为如果您有一个选择,也许您只想阻止该选择(在另一个阻止注释中!)。
演示:(1)仅是第一种方法,其中selectby
选择文本并手动将其关闭,然后(2)使用宏版本一步完成。