'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?



Solution 1:[1]

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

Solution 2:[2]

How to comment out multiline / single line in VS Code:


MacOS:

Shift + Option + A:

/* multiline    
   comment */

CMD + /:

// single line comment    

Windows:

Shift + Alt + A:

 /* multiline
    comment */

CTRL + /:

// single line comment

How to remap / change these shortcuts?

Windows: File > Preferences > Keyboard Shortcuts.

MacOS: Code > Preferences > Keyboard Shortcuts.

You can search through the list both by keybindings (key names) and command names.


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

Official docs: Key Bindings for Visual Studio Code

Solution 3:[3]

The keyboard shortcut to comment multiple in Windows is shift+alt+A.

Solution 4:[4]

In my case, Ubuntu, the shortcut is ctrl+shift+A.

Solution 5:[5]

You can see all available keybindings on the official documentation.

Here's the relevant bit for osx:

Key     Command

?K ?C   Add Line Comment    
?K ?U   Remove Line Comment 
?/      Toggle Line Comment 
??A     Toggle Block Comment

You will need to select the lines you want to comment first, then execute above shortcut, i.e. ?/ on osx Ctrl/ on Windows.

Solution 6:[6]

In MacOS comment out multi-lines in Visual Studio Code by keyboard shortcut:

Option + Shift + A

/*
...
...
*/

Or,

Select all lines and then press CTRL + /

Solution 7:[7]

Try option 1 first. If it doesn't work for you then try option 2 which is the actual shortcut for VS Code:

Option 1. Alt / Option + Shift + A

Option 2. While the text is selected hit Ctrl / Cmd+K and then Ctrl / Cmd+C.

As of now (version 1.16.3), you can check all available keyboard shortcuts by going into File > Preferences > Keyboard shortcuts. Here you can search for shortcuts related to code comments.

For users who are coming from Sublime Text or likes to have Ctrl+Shift+/, you can make the change from the above mentioned settings panel or simply install the Sublime Text Keymap extension by Microsoft.

Update: As VS Code has become pretty much standard editor for almost everything these days, I would say picking option 1 is always helpful.

Solution 8:[8]

For my keyboard layout it's Ctrl + § for:

//
//
//

And Shift + Alt + A for:

/*
...
*/

Solution 9:[9]

To comment multiple line on visual code use

shift+alt+a

To comment single line use

ctrl + /

Solution 10:[10]

For me to comment I use:

Ctrl + k, Ctrl + c

and to uncomment:

Ctrl + k, Ctrl + u

I am using ubuntu 18.0.4

Solution 11:[11]

  1. Select all line you want comments

  2. CTRL + /

Solution 12:[12]

Win10 with French / English Keyboard CTRL + / , ctrl+k+u and ctrl+k+l don't work.

Here's how it works:

/* */ SHIFT + ALT + A

// CTRL + É

É key is next to right Shift.

Solution 13:[13]

CTRL + SHIFT + A for CSS multiline

  • Ubuntu 16
  • VSCode Version 1.17.2

Solution 14:[14]

All the key board shorcuts for VS code can be found in the link : Link

  • Add a Line comment Ctrl+K Ctrl+C
  • Remove a line comment Ctrl+K Ctrl+U
  • More shortcut Ctrl+/

Solution 15:[15]

If you are using VSCode in a linux environment, then you can comment multiple lines by either:

Selecting a block of code => then, press Ctrl + Shift + A (Block commenting)

Or, selecting a block of code => then, press Ctrl + / (Single-line commenting applied to all selected lines)

Hope this helps.

Solution 16:[16]

In the new version of VSCODE ( version 1.26.1)

VSCODE Version

  1. Go to File > preferences > Keyboard Shortcuts
  2. Search for comment Double click the existing shortcut 'keybinding`
  3. And press the new keyboard shortcut in my case ctrl + shfit + /

You can assign any shortcuts you want. Hope it helps.

enter image description here

Solution 17:[17]

You can find the shortcut in the Edit menu :

Edit > Toggle Block Comment => Shift-Alt-A

Solution 18:[18]

visual studio 2017 we do a: Comment Selection

Ctrl+K, Ctrl+C

press Ctrl+K to get shortcut. press Ctrl+C to confirm http://visualstudioshortcuts.com/2017/

Solution 19:[19]

For multiline commenting in Python VSCode, all you have to do it just:

Ctrl + /

Solution 20:[20]

On Windows 10 you can use CTRL + } to comment/uncomment on any line or block of code.

enter image description here

Solution 21:[21]

For doing on mac: CMD + Shift + 7

Solution 22:[22]

For me it was ctrl + ' (I am using a swedish layout for the keyboard). Hope that helps anyone.

Solution 23:[23]

In windows you need to press ctrl + / in mac you can do ? + / to make multiple comment

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

Then if you want to un-comment then select the lines again and then press ctrl + /(in windows) again ? + /(in mac).

Solution 24:[24]

enter image description here

Select lines which you want to Comment

Then press Ctrl + / to make selected lines comment

enter image description here

And to uncomment:
Select the commented lines you which want to uncomment
First press Ctrl + K then Ctrl + Uto make commented lines uncomment

Solution 25:[25]

1.Select the text, Press Cntl + K, C to comment (Ctr+E+C ) 2.Move the cursor to the first line after the delimiter // and before the Code text. 3.Press Alt + Shift and use arrow keys to make selection. ... 4.Once the selection is done, press space bar to enter a single space.

Solution 26:[26]

Multi-Line Comment in VS Code

To comment the code select the lines and hit: Alt + Shift + A

To Uncomment select the commented code and hit: Alt + Shift + A

enter image description here

Solution 27:[27]

For windows, the default key for multi-line comment is Alt + Shift + A

For windows, the default key for single line comment is Ctrl + /

Solution 28:[28]

CTRL + SHIFT + A For Red Hat,centos

  • Select item
  • then CTRL+SHIFT+A

Solution 29:[29]

CTRL + / comment / uncomment multiple lines of code

Ctrl+k+u for upper case latter

ctrl+k+l for lower case latter