VSCode可以逐行进行块注释吗?

问题描述 投票:0回答:1

这是我使用ctrl + /在VS Code中注释HTML代码的示例:


    <!-- </label>
    <label>Confirm Your Email:
        <!-- <input type="email" name="emailConfirm" required>
    <!-- </label>
    <label> -->
        <input type="checkbox" name="termsAgree" required/>
            I agree to the <a href="/legal/terms/">Terms & Conditions</a>. -->
    </label> -->

  1. 选择整个代码块并ctrl+/注释整个内容
  2. 选择了一段代码,然后将ctrl+/注释为[[un],但只添加了一个新注释,从而破坏了较大的注释
  3. 再次执行#2,现在是一场噩梦
  • 当我ctrl + / CSS代码块时,我有同样的问题。 PHP代码中没有问题,因为它使用//逐行注释

    如何更改此行为?

    我在想:

      可以使用阻止注释并“知道”当前是否在注释中的“智能”注释器
  • 一个愚蠢的评论者,只像这样单独注释/取消注释每一行:
  • <!-- </label> --> <!-- <label>Confirm Your Email: --> <!-- <input type="email" name="emailConfirm" required> --> </label> <label> <!-- <input type="checkbox" name="termsAgree" required/> --> <!-- I agree to the <a href="/legal/terms/">Terms & Conditions</a>. --> <!-- </label> -->
    [请忽略html无效的事实。我只是在此示例中使用了一个随机块。    
  • visual-studio-code comments keyboard-shortcuts
    1个回答
    1
    投票
    是的,vscode可以逐行阻止注释,但是该功能不是内置的。您将不得不使用宏命令,在这里我使用了multi-command,以将各行分开并在每个行上加上一个块注释。

    将其放入您的settings.json

    "multiCommand.commands": [ { "command": "multiCommand.blockHTMLCommentByLine", "sequence": [ "editor.action.insertCursorAtEndOfEachLineSelected", "cursorHomeSelect", "editor.action.blockComment", "cancelSelection", ] } ]

    它会将您的选择分成几行,然后在每一行之间切换块注释。 

    添加键盘绑定以触发该宏-重载

    ctrl + /键盘绑定(将其放入keybindings.json中:]

    { "key": "ctrl+/", "command": "extension.multiCommand.execute", "args": { "command": "multiCommand.blockHTMLCommentByLine" }, // "when": "editorTextFocus && editorHasSelection && resourceExtname =~ /\\.(html|css|scss)/" "when": "editorTextFocus && editorHasSelection && resourceExtname =~ /\\.html/" },
    我将其限制为.html文件,但您可以看到如何在其他when子句中包括其他扩展名。

    演示:

    toggle block comments each line


    如果要注释整行,则必须选择完整的行。
    © www.soinside.com 2019 - 2024. All rights reserved.