Reputation:
Old way with CTRL + K CTRL + C works for commenting but old way CTRL + K CTRL + U not working anymore for uncomment, if anyone know new shortcut I will be grateful. Thanks.
Upvotes: 65
Views: 188217
Reputation: 154
ctrl + /
can be used for both commenting and uncommenting. This is for windows machine.
Upvotes: 1
Reputation: 329
On Visual Studio 2022, the only thing that works for me is Ctrl+Shift+/ and that only works on highlighted code (rather than like all normal IDEs that would do this on the line that the caret/cursor is already on)
Also it only seems to work on .cs files, not xml or xaml.
To fix this, or customize it to something more intuitive that you'd prefer, go to Tools
-> Options
, and under Environment
there's a section called Keyboard
. Search for commands containing the word "comment", and you'll see:
Edit.CommentSelection and Edit.UncommentSelection, but I recommend changing the one for Edit.ToggleLineComment, and assigning a shortcut so that it works for commenting and uncommenting alike.
Change those to keyboard shortcuts you prefer (typically Ctrl + /
which is normal on most IDEs), or at least you can see which ones are set for your Visual Studio at that moment. As mentioned sometimes these get changed from the defaults when plugins/extensions are installed.
Note this only works on .cs files, I could not figure out a way to get it to work on .xml and .xaml files as well, even though I set the keyboard shortcut as "Global", and even adding one for XAML specifically didn't seem to do anything. However this was an improvment since I could at least comment/uncomment using a single shortcut that I'm more accustomed to.
Upvotes: 0
Reputation: 112
Use CTRL+/ for both comment and uncomment.
Also here is the cheatsheet with all shortcuts. https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
Upvotes: 0
Reputation: 167
you can use
Ctrl + /
for both comment and uncomment the code in vscode
Upvotes: 0
Reputation: 71
I recommend instead of using separate shortcuts for add/remove comment to set toggle line/block comment with the same shortcut so it also remove comment when the line/block is commented out:
editor.action.commentLine
editor.action.blockComment
Upvotes: 1
Reputation: 1959
In windows system, below commands works for me for comment and uncomment in VS CODE-
CTRL + K
--- to comment OR CTRL + /
---to comment
CTRL + /
--- to uncomment
Upvotes: 4
Reputation: 1388
I had the same problem. In the newer version its actually CTRL+/ to uncomment.
Upvotes: 48
Reputation: 595
Take care. Some extensions change the keyboard shortcuts. Take a look in the attached screenshot. I don't know what extension changed mine to Shift + Ctrl + K on Windows.
Upvotes: 2
Reputation: 145
I'm using VS code on Mac, Version: 1.49.0 and I had similar problem. In my case shortcut "cmd + k, cmd + u" made text uppercase. It turned out I have two commands assigned to this shortcut. In "Keyboard Shortcuts" you can also filter by shortcuts (or "Keybindings") by pressing keyboard icon on the right in the search bar, it will record keys:
To fix this, I just changed "Transform to Uppercase" Keybinding to something else as I rarely use it.
Upvotes: 1
Reputation: 1267
In windows Inorder to comment and uncomment the code in VS CODE
Upvotes: 9
Reputation: 664
For Mac OS just select all the stuff you want to comment or uncomment and press Command + /
Upvotes: 1
Reputation: 3303
Mac OS you can use COMMAND
+ /
for commenting and uncommenting
Upvotes: 14
Reputation: 41
On Windows, I am using strg + #
It's a default shortcut in VSCode --> toggle line comment but it works also for blocks.
Upvotes: 3
Reputation: 77285
I just updated my VSCode to the version you mentioned. The combinations work exactly as you described. It must be something that was changed on your computer.
Go to File => Preferences => Keyboard Shortcuts
(Or press CTRL + K and then CTRL + S)
look for Remove Line Comment
. In my settings it still says
If your VSCode has a different keybinding, change it back to what you want.
Upvotes: 61