首页 文章

如何在Visual Studio代码中注释多行?

提问于
浏览
178

我找不到在Visual Studio Code中评论和取消注释多行代码的方法 .

是否可以使用某种快捷方式在Visual Studio代码中注释和取消注释多行?如果是的话,该怎么办?

23 回答

  • 133

    Shift + Alt + A

    在这里,您可以找到所有键盘快捷键 .

    All VSCode Shortcuts

    PS:我更喜欢 Ctrl + Shift + / 来切换块注释,因为 Ctrl + / 是切换行注释的快捷方式所以's naturally easier to remember. To do so, just click on the settings icon in the bottom left of the screen and click '键盘快捷键'并找到"toggle block..." . 然后单击并输入所需的组合 .

  • 4
    • 选择要评论/取消评论的行

    • 执行命令 editor.action.commentLine (Windows上的默认快捷方式: CTRL + /

    or

    分别执行命令 editor.action.addCommentLine (Windows上的默认快捷方式: ctrl+k ctrl+ceditor.action.removeCommentLine (Windows上的默认快捷方式: ctrl+k ctrl+u

    见官方文件:Key Bindings for Visual Studio Code

  • 0

    在Windows中注释多个的键盘快捷键是shift alt A.

  • 1

    在我的情况下,Ubuntu,快捷方式是ctrl shift A.

  • 25

    如何在VS代码中注释掉多行/单行:


    MacOS:

    转换选项A:

    /* multiline    
       comment */
    

    CMD /:

    // single line comment
    

    Windows:

    Shift Alt A:

    /* multiline
        comment */
    

    CTRL /:

    // single line comment
    

    如何重新映射/更改这些快捷方式?

    Windows: 文件>首选项>键盘快捷键 .

    MacOS: 代码>首选项>键盘快捷键 .

    您可以通过键绑定(键名称)和命令名称搜索列表 .


    Read: How to set shortcuts from another text editor (Sublime, Atom etc)?

    Official docs: Key Bindings for Visual Studio Code

  • 2

    您可以在官方documentation上查看所有可用的键绑定 .

    这是osx的相关位:

    Key     Command
    
    ⌘K ⌘C   Add Line Comment    
    ⌘K ⌘U   Remove Line Comment 
    ⌘/      Toggle Line Comment 
    ⇧⌥A     Toggle Block Comment
    

    您需要先选择要注释的行,然后执行上面的快捷方式,即在Windows上的osx Ctrl/⌘/ .

  • 84

    对于我的键盘布局,它是Ctrl§:

    //
    //
    //
    

    和Shift Alt A:

    /*
    ...
    */
    
  • 1

    CTRL + SHIFT + A 用于CSS多行

    • Ubuntu 16

    • VSCode版本1.17.2

  • 75

    在Visual Studio Code中的 MacOS comment out multi-lines 键盘快捷键:

    选项转移A.

    /*
    ...
    ...
    */
    
  • 31
    • 选择您想要评论的所有行

    • CTRL /

  • 5

    CTRL + SHIFT + A 对于Red Hat,centos

    • 选择项目

    • 然后CTRL SHIFT A.

  • 1

    对我来说这是 ctrl + ' (我使用瑞典语版面键盘) . 希望能帮助任何人 .

  • 2

    1.选择文本,按Cntl K,C进行注释(Ctr E C)2 . 将光标移动到分隔符//之后的第一行和代码文本之前 . 3.按Alt Shift并使用箭头键进行选择 . ... 4.选择完成后,按空格键输入单个空格 .

  • 13

    视觉工作室2017我们做了一个:评论选择

    Ctrl+K, Ctrl+C
    

    按Ctrl K以获取快捷方式 . 按Ctrl C确认http://visualstudioshortcuts.com/2017/

  • 2

    在视觉代码上使用注释多行

    shift+alt+a
    

    评论单行使用

    ctrl + /
    
  • 6

    您可以使用与以下相同的步骤查看现有快捷方式 . 我发现默认的不方便,所以我使用以下过程来更改IDE以使用注释中看到的'/'命令 .

    您可以通过进入“工具”菜单并选择“选项”来自定义键盘快捷键 . 然后从“环境”分支中选择“键盘” . 从那里,您可以将Edit.CommentSelection和Edit.UncommentSelection命令绑定到您想要的任何键盘快捷键 .

  • 1

    CTRL / comment /取消注释多行代码

    ctrl k u for upper case after

    ctrl k l为小写后者

  • 1

    在mac上做:CMD Shift 7

  • 2

    截至目前(版本1.18.0),您可以通过转到文件>首选项>键盘快捷方式来检查键盘快捷方式 . 在这里,您可以搜索与评论相关的快捷方式 .

    对于来自 Sublime Text 或喜欢使用Ctrl Shift /的用户,您可以从上述设置进行更改,或者只需安装Microsoft的 Sublime Text Keymap 扩展名即可 .

  • 27

    在Windows 10,意大利语键盘,VSC 1.19.1:

    选择要评论的行,然后按“Ctrlù”

  • 3

    Win10与法语/英语键盘CTRL /,ctrl k u和ctrl k l不起作用 .

    以下是它的工作原理:

    / * * / SHIFT ALT A //CTRLÉ

    É键位于右侧Shift旁边 .

  • 1

    在新版本的VSCODE(版本1.26.1)中

    VSCODE Version

    • 转到文件>首选项>键盘快捷键

    • 搜索 comment 双击现有快捷键'keybinding`

    • 在我的情况下按下新的键盘快捷键 ctrl + shfit + /

    您可以指定所需的任何快捷方式 . 希望能帮助到你 .

    enter image description here

  • 1

    在Windows中你需要在mac中按 ctrl + / 你可以做 Command ⌘ + / 进行多个评论

    // public function index()
    // {
    //     $badgeIcon = BadgeIcon::all();
    //     return $this->showAll($badgeIcon);
    // }
    

    然后,如果要取消注释,请再次选择行,然后再次按 ctrl + / (在Windows中) Command ⌘ + / (在mac中) .

相关问题