Search code examples
visual-studio-codekeyboard-shortcuts

How can I comment multiple lines in Visual Studio Code?


I cannot find a way to comment and uncomment multiple lines of code in Visual Studio Code.

Is it possible to comment and uncomment multiple lines in Visual Studio Code using some shortcut? If yes, how to do it?


Solution

  • First, select the lines you want to comment/uncomment (Ctrl + L is convenient to select a few lines)

    Then:

    • To toggle line comments, execute editor.action.commentLine (Ctrl + / on Windows)

      or

    • To add line comments, execute editor.action.addCommentLine (Ctrl + K, Ctrl + C)

      To remove line comments, execute editor.action.removeCommentLine (Ctrl + K, Ctrl + U)

      or

    • To toggle a block comment, execute editor.action.blockComment (Shift + Alt + A)

    See the official documentation: Key Bindings for Visual Studio Code