VS Code:选择或删除未选择文本的块注释的快捷方式

2024-01-02

I know there is a shortcut for comment and uncomment code block (SHIFT + ALT + A), but is there a way to quickly select (or even remove without select) block comment without using mouse or keyboard to select and press the delete/backspace button? For example:

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

有没有可以放置光标的键盘快捷键块注释中的任意位置只需敲击几下键盘即可将其删除?谢谢!


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

首先,使用优秀的选择依据 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) 使用宏版本一步完成此操作。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

VS Code:选择或删除未选择文本的块注释的快捷方式 的相关文章

随机推荐