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?
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?
Windows: Shift+Alt+A
Linux: Shift+Ctrl+A
Here you can find all the keyboard 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.
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
How to comment out multiline / single line in VS Code:
Shift + Option + A:
/* multiline
comment */
CMD + /:
// single line comment
Shift + Alt + A:
/* multiline
comment */
CTRL + /:
// single line comment
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
The keyboard shortcut to comment multiple in Windows is shift+alt+A.
In my case, Ubuntu, the shortcut is ctrl+shift+A.
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.
In MacOS
comment out multi-lines in Visual Studio Code by keyboard shortcut:
Option + Shift + A
/*
...
...
*/
Or,
Select all lines and then press CTRL + /
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.
For me to comment I use:
Ctrl + k, Ctrl + c
and to uncomment:
Ctrl + k, Ctrl + u
I am using ubuntu 18.0.4
For my keyboard layout it's Ctrl + § for:
//
//
//
And Shift + Alt + A for:
/*
...
*/
To comment multiple line on visual code use
shift+alt+a
To comment single line use
ctrl + /
All the key board shorcuts for VS code can be found in the link : Link
CTRL + SHIFT + A for CSS multiline
For multiline commenting in Python VSCode, all you have to do it just:
Ctrl + /
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/
In the new version of VSCODE ( version 1.26.1)
comment
Double click the existing shortcut 'keybinding` You can assign any shortcuts you want. Hope it helps.
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.
You can find the shortcut in the Edit menu :
Edit > Toggle Block Comment => Shift-Alt-A
For me it was ctrl + ' (I am using a swedish layout for the keyboard). Hope that helps anyone.
Select lines which you want to Comment
Then press Ctrl + / to make selected lines comment
And to uncomment:
Select the commented lines you which want to uncomment
First press Ctrl + K then Ctrl + Uto make commented lines uncomment
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).
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.
CTRL + SHIFT + A For Red Hat,centos
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
Keyboard shortcuts for VSCode on MacOS: https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf
I use ⌘/ to toggle commenting.
To change the setting on VS2019:
Tools->Options
Search for Keyboard
Under Show Commands Containing
search for ToggleLineComment
See what it is set to or change to whatever you like.
VERY IMPORTANT: sometimes it is required to select
TextEditor
and notGlobal
. this killed me for hours.
You can view the existing shortcuts using the same steps as below. I find the default ones to be inconvenient, so I used the following process to change the IDE to use the '/' command seen in the comments.
You can customize the keyboard shortcuts by going int the "Tools" menu and selecting "Options". Then select "Keyboard" from the "Environment" branch. From there you can bind the Edit.CommentSelection and Edit.UncommentSelection commands to whichever keyboard shortcuts you'd like.
In Windows
Select the lines you want to comment. Then press Ctrl + /
on Windows 10, Italian Keyboard, VSC 1.19.1:
Select lines that you want comment and press "Ctrl + ù"
This is somewhat of an extension to the answer when the comment line is too long to fit on a line (above 80 chars or whatever). If the comment is too long and text needs to wrap, it's better to keep it under control (rather than use the editor's text wrap feature). This plugin Rewrap helps do just that https://marketplace.visualstudio.com/items?itemName=stkb.rewrap&ssr=false#review-details
Install the plugin in VS Code, select the text comment, comment it using one of the right methods described in the answers (Ctrl + / is easiest) and then once it's commented, press Alt + Q and this will split the text to multiple lines and also comment it. Found it pretty useful. Hope this helps someone :)
for add cltr + ù to comment , go to shortcut and search ctrl + shift + 7 (default comment enabled ) or search comment , right-click on shortcut > add shortcut key [ctrl + k ctrl + a ] ( is equivalent to aggiungi tasto di scelta rapida [ctrl + k ctrl+a ] ) , press the keys : ctrl + ù > enter .
should add a new line like this ( line above the one clicked ).
For powershell it's CTRL + #
. So basically, select your lines and use a combination of CTRL +
the sign to comment of the code. PWS is #, C# is /.. and so on.
To define shortkey Ctrl + Alt + / to mutiplelines comment
Add this to your keybindings.json
:
{
"key": "ctrl+alt+oem_2",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
On my version of visual studio code and windows it is to insert """ in the following way
"""This is the code i want to comment out
over several lines
I want to comment it out
"""
or also the shourtcut alt+shift+a