hello
hello

Reputation: 127

Commenting out code does not work properly in VS code

I used to able to comment or uncomment multiple lines of code by pressing ctrl+/

# x = 10 
# print(x)

But now I press ctrl+/, it becomes the following:

...

I tried to search for solution online, and I believe it is because the Windows shortcut somehow overwrite the shortcut in VS code. But I cannot find a solution.

I tried:

1.Reset the shortcut

2.Reinstall VS code

They don't work. Any help is appreciated.

Upvotes: 11

Views: 47091

Answers (10)

Tin Pritišanac
Tin Pritišanac

Reputation: 409

vscode screenshot

For me source language change to english did the trick.

Upvotes: 0

Varesh
Varesh

Reputation: 1758

I also had the same issue on my mac and the solution was that I was missing the language support. I was working with terraform and once I installed the corresponding plugin, it worked like as it should, plain normal.

So I guess the reasons could be many, check shortcuts, check language support, etc.

Upvotes: 1

MattFace
MattFace

Reputation: 335

I had the same problem but it was not caused by the keyboard layout.

I verified this by selecting Edit > Toggle Line Comment & Edit Toggle Block comment from the UI, and nothing was happening.

For me it turned out that i had somehow disabled built in php support (probably to use some extension).

so the solution was to go to Extensions. Search for "@builtin php" Enable PHP Language Features and PHP Language Basics.

Upvotes: 0

SlyGuy
SlyGuy

Reputation: 117

I had this issue and because I installed Notepad++ keymap extension a while ago and forgot about it. Disabling the Notepad++ keymap extension and restarting VS Code solved the problem.

Upvotes: 0

lzxsmtt
lzxsmtt

Reputation: 1

Open Settings, find keyboard on Application/Keyboard change Keyboard: Dispatch code to keyCode.

Upvotes: 0

Hijas
Hijas

Reputation: 1

go to keyboard short cuts search for toggle line comment

check when expression in when column

right click on the when expression and edit and paste "editorTextFocus && !editorReadonly"

Upvotes: 0

questionto42
questionto42

Reputation: 9610

As already said, you might just have another keyboard layout. Check the menu to see which shortcut you need to press. For example, Toggle line comment is Ctrl+# here:

enter image description here

(By mistake, I had thought at first that I can handle the shortcuts only if I stick to the US-ENG keyboard layout to have Ctrl+/ back. Not needed; check your menu in the other layout.)

Upvotes: 2

subodhkalika
subodhkalika

Reputation: 2247

First of all see which keyboard layout you are using on your System. Change the Keyboard layout to US-Keyboard if US keyboard is not selected.

If it is US keyboard then,

The shortcut key might have changed.

You can edit your preferences on VS code.

  1. Goto File > Preferences > Keyboard Shortcuts

  2. Search for Toggle Line Comments.

  3. Click on edit icon and press your desired shortcut key

It could also be caused due to the same key bindings for shortcuts.The Keyboard Shortcuts editor has a context menu command Show Same Keybindings, which will filter the keybindings based on a keyboard shortcut to display conflicts. To view same key bindings follow the above steps till Step 3. Now right click on the Toggle Line commands and click Show same key bindings.

Upvotes: 18

tcf01
tcf01

Reputation: 1789

I encounter this problem before. You should press shift key to switch back to type English and try again.

Upvotes: 5

It depends on what language you are programming. But if you want to type # character you can hold down shift key and press number 3 on your keyboard.

Upvotes: -2

Related Questions