user9160346
user9160346

Reputation:

What is shortcut for uncomment in Visual Studio Code?

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

Answers (18)

Santosh sanwal
Santosh sanwal

Reputation: 154

ctrl + / can be used for both commenting and uncommenting. This is for windows machine.

Upvotes: 1

Papyrus
Papyrus

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.

enter image description here

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

Mithun Wijayasiri
Mithun Wijayasiri

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

Niraj Gautam
Niraj Gautam

Reputation: 167

you can use

Ctrl + /

for both comment and uncomment the code in vscode

Upvotes: 0

zemiacsik
zemiacsik

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

Jaydeep Shil
Jaydeep Shil

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

Egon Allison
Egon Allison

Reputation: 1388

I had the same problem. In the newer version its actually CTRL+/ to uncomment.

Upvotes: 48

Ricardo Maroquio
Ricardo Maroquio

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.

enter image description here

Upvotes: 2

Priyanka Vadhwani
Priyanka Vadhwani

Reputation: 1155

For windows:

Remove Comment Line:- ctrl+k ctrl+u

Upvotes: 6

Tom K
Tom K

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:

enter image description here

To fix this, I just changed "Transform to Uppercase" Keybinding to something else as I rarely use it.

Upvotes: 1

Bathri Nathan
Bathri Nathan

Reputation: 1267

In windows Inorder to comment and uncomment the code in VS CODE

  1. CTRL + K ========> to comment the code
  2. CTRL + / ========> to uncomment the code

Upvotes: 9

krul
krul

Reputation: 2269

What worked for me is : CTRL + Shift + K enter image description here

Upvotes: 1

Sagar Barapatre
Sagar Barapatre

Reputation: 664

For Mac OS just select all the stuff you want to comment or uncomment and press Command + /

Upvotes: 1

Unnikrishnan
Unnikrishnan

Reputation: 3303

Mac OS you can use COMMAND + / for commenting and uncommenting

Upvotes: 14

Markus Morley
Markus Morley

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

Ashutosh Dash
Ashutosh Dash

Reputation: 610

use ctrl+ / to uncomment in VS Code.

Upvotes: 4

Bened
Bened

Reputation: 329

CTRL+/

Note that this is the / on the numeric keypad!

Upvotes: 18

nvoigt
nvoigt

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

enter image description here

If your VSCode has a different keybinding, change it back to what you want.

Upvotes: 61

Related Questions