VS 代码:select 的快捷方式或删除没有文本 selected 的块注释

VS Code: Shortcut to select or remove Block Comment with no text selected

我知道有一个注释和取消注释代码块的快捷方式(SHIFT + ALT + A), 但有没有一种方法可以快速 select (甚至不用 select 删除)阻止评论而不使用鼠标或键盘到 select 并按下 delete/backspace 按钮?例如:

/* 
This is a large block of code with at least 50 lines of code!
   :
   :
*/

是否有键盘快捷键,我可以将光标 放在块注释 的任意位置,然后只需敲几下键盘就可以将其删除?谢谢!

您可以设置一个宏来轻松完成此操作。

首先,使用出色的 Select By 扩展 (@rioV8) 来 select 块注释标记 /**/ 之间的文本(包括块注释标记)。将他的放入您的设置中:

"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"
},

你可以在这里停下来,使用你的键绑定到 select 文本,然后 Shift+Alt+A 关闭块注释。

或者您可以将 selectby.regex1 添加到宏中,然后一步完成 selection 和切换。这里使用宏扩展 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"
},

这里我使用了Shift+Alt+A来触发宏。我使用了 when 子句 !editorHasSelection 因为如果你有一个 selection 可能你只想阻止评论 selection (在另一个块评论中!!)。

演示:(1) 只是第一种方法,其中 selectby select 是您的文本,您手动将其关闭,然后 (2) 使用宏版本一步完成.