Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to 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?

like image 508
gog Avatar asked Dec 16 '15 15:12

gog


People also ask

How do you comment multiple lines in code?

To comment out multiple code lines right-click and select Source > Add Block Comment. ( CTRL+SHIFT+/ ) To uncomment multiple code lines right-click and select Source > Remove Block Comment. ( CTRL+SHIFT+\ )

How do you mass comment on Vscode?

To comment out an entire block of code: Select the code and select Toggle Line Comment(s) from the context menu.

How do I comment a few lines in Visual Studio?

Windows: Ctrl + K + U. Mac: Command + K + U.


2 Answers

Shift+Alt+A

Here you can find all the keyboard shortcuts.

All VSCode Shortcuts

PS: I prefer Ctrl+Shift+/ for toggling block comments because Ctrl+/ is shortcut for toggling line comments so it's naturally easier to remember. To do so, just click on the settings icon in the bottom left of the screen and click 'Keyboard Shortcuts' and find "toggle block...". Then click and enter your desired combination.

like image 185
saran3h Avatar answered Sep 30 '22 20:09

saran3h


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 doc : Key Bindings for Visual Studio Code

like image 22
Wosi Avatar answered Sep 30 '22 20:09

Wosi