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?
Shift+Alt+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
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.
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/
All the key board shorcuts for VS code can be found in the link : Link
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.57.0), you can check all available keyboard shortcuts by going to 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 setting or simply install the Sublime Text Keymap
extension by Microsoft.
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).