In previous article, I have mentioned Useful Visual Studio Shortcuts (comment, remove comment, Collapse code etc ) but in this article, I have mentioned how to comment out multiple lines in Visual Studio Code.

Comment out multiple lines of selected code

Method:1

Here are the simple steps, to comment out or uncomment multiple lines of code in Visual Studio Code IDE.

  1. If the file is already opened in Visual Studio Code. Select a block of code using your mouse or keyboard
  2. Then you can simply click on "Alt+Shift+A" in Windows or "Ctrl + Shift +A" in Mac to comment or uncomment selected lines, as you can see in given image
    multiple-lines-comment-uncomment-vs-code
  3. On Ubuntu, the shortcut is Ctrl + Shift + A, similar to Mac.

Method 2:

In Windows

You can also CTRL + K  and then CTRL + C to comment multiple lines

For uncommenting multiple lines you can use CTRL + K then CTRL + U

On Mac

You can use CMD + K + C  to comment multiple lines

CMD + K + U to uncomment multiple lines.

Method 3:

Simply use 'Ctrl + /' for commenting and uncommenting code in VS Code Windows and To toggle a block comment, execute editor.action.blockComment (SHIFT + ALT + A)

On Mac, the shortcut is: Command + /

Usually, as you can see from above shortcuts in VS Code comment shortcuts, Mac is very similar to the Windows version.

Changing the comment shortcut in VS Code

You can also customise the comment shortcuts in VS Code.

By navigating to

  • Windows : File -> Preferences -> Keyboard Shortcuts.
  • MacOS : Code -> Preferences -> Keyboard Shortcuts.

You can search through the list both by keybindings (key names) and command names, and update them according to what you like.

Format code shortcut in VS Code

I would like to mention another useful shortcut for VS Code, which is to format code:

  • On Windows - Shift + Alt + F
  • On MacOS - Shift + Option + F
  • On Ubuntu - Ctrl + Shift + I

Comment Single line Code in VS Code

You can use following shorcuts to comment single line code in Visual Studio(VS) Code:

  • Add a Line comment Ctrl+K, Ctrl+C (Windows)
  • Remove a line comment Ctrl+K, Ctrl+U (Windows)
  • In Mac OS , we can use COMMAND + / for commenting and uncommenting for single line in VS Code.

That's it, hope it helps.

You may also like to read:

Best IDE for Web-developement(C#, ASP.NET, PHP, Java, HTML, CSS)

Useful Visual Studio Plugins

Best Source Code Management tools (Version Control tools)

Best AWS S3 Free Alternatives

Best Project Management Software (Scrum tools) to use.

5+ Best Visual Studio Alternatives