我找不到在Visual Studio code中注释和取消注释多行代码的方法。

是否可以在Visual Studio Code中使用一些快捷方式注释和取消注释多行?如果有,怎么做?


当前回答

首先,选择要注释/取消注释的行(CTRL+L可以方便地选择几行)

然后:

要切换行注释,执行editor.action.commentLine (Windows下的CTRL+/) 或 要添加行注释,执行editor.action.addCommentLine (CTRL+K CTRL+C) 要删除行注释,执行editor.action.removeCommentLine (CTRL+K CTRL+U) 或 要切换块注释,请执行editor.action.blockComment (SHIFT-ALT-A)

参见官方文档:Visual Studio Code的键绑定

其他回答

对于windows,多行注释的默认键是Alt + Shift + A

对于windows,单行注释的默认键是Ctrl + /

在windows中,您需要按ctrl + /在mac中,您可以使用⌘+ /进行多个注释

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

然后如果你想取消注释,那么再次选择这些行,然后再次按ctrl + /(在windows中)⌘+ /(在mac中)。

您可以在官方文档中看到所有可用的键绑定。

这是osx的相关位:

Key     Command

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

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

在Windows中,注释多个的快捷键是shift+alt+A。

visual studio 2017我们做了一个:评论选择

Ctrl + K, Ctrl + C

按Ctrl+K快捷键。按Ctrl+C确认 http://visualstudioshortcuts.com/2017/