'VS Code's toggle-comment Keyboard Shortcut isn't working when I use Jupyter Notebooks

The default VS Code keybinding for toggling line comments isn't working in Jupyter Notebooks. The shortcut Ctrl+/ works fine when I use it in .py files, and it seems to work everywhere else as well. But when I am in a *.ipynb file, it just doesn't work. I noticed that when I use the browser VSCode version, the shortcut works in *.ipynb files.

I thought that changing the keybinding to something different might help solve the issue, but to no avail.

I tried recreating my project-environment. I recreated everything in new files, and in new folders. I even tried reinstalling VS Code. Nothing has worked for me.



Solution 1:[1]


VS Code Provides a Tool for Troubleshooting this Exact Issue


        I have answered questions about VS Code Keyboard Shortcuts several times, and what I learned from the experience, is that most people seem to prefer hitting there heads against a wall, rather than using the tool that VS Code developers graciously provided for them (or us I mean).

The Tool is named Keyboard Shortcuts Troubleshooter, and it is Toggled ON/OFF via a native VSC command. The command can be found in VS Code's "Quick Input Drop-down Menu". To execute the command, you need to open the Quick Input Menu using the F1 Key. Once the menu opens, your editor will change focus to its text-input, so you don't have to do anything other than simply typing the bold line of text below.

"Developer: Toggle Keyboard Shortcuts Troubleshooting"

While typing an option with the same name as what you are typing will appear in the menu. (PLEASE NOTE: _there are a few troubleshooters, one for keyboard shortcuts, and a couple others that pertain to Notebooks (DO NOT USE ANY TROUBLESHOOTER BUT THE KEYBOARD SHORTCUTS TROUBLESHOOTER).

Once you have found, and selected the "Developer: Toggle Keyboard Shortcuts Troubleshooting" command in the quick menu, the troubleshooter will be active.

PLEASE NOTE: SELECTING THE TROUBLESHOOTER TWICE WILL DEACTIVATE IT AND YOU WILL BE LEFT AT WHERE YOU STARTED.

To view the tool's output, you'll need to change your panel's view from terminal to the Output Console by selecting output at the top of your panel. Vs-code might automatically do this for you though. It didn't use to, but I think it does open the correct output window when you execute the +"Developer: Keyboard Shortcuts Troubleshooting"_ command. If it doesn't, then make sure you select LOG(Window) from the drop-down at the top-right of the Output-console's panel.

With the troubleshooter active, and the output open, use a keybinding (any keybinding) to test it. The output looks like this.



You Should have the Troubleshooter Working, which will give you all the info you need to understand the issue you have.

Bellow I have provided a snippet showing what the Output console looks like when I executed my custom Save-all Keybinding. So that your not completely on your own, your going to want to visit two links, if your able to be self-taught, these links golden.

  1. The first is a guide. I provided this link, because if you can't get your troubleshooter working, this link provides a VS Code documented guide on how to use it. Plus a wealth of other info on this subject. [CLICK HERE]

  2. The second is a Microsoft/VSCode/Wiki. Its covers this topic in a context that's has a little more depth to it. Over all I find this page very helpful, but it is a more advanced resource. [Click Here]

Click on the links that say CLICK HERE, the others go to the generic sites.

This output is for the keys:

[CTRL]+[SHIFT]+[SPACE]   [S]

It saves all files when pressed. And this is the output for that keybinding I just described.

> / Received  keydown event - modifiers: [ctrl,shift], code: Space, keyCode: 32, key:  
> | Converted keydown event - modifiers: [ctrl,shift], code: Space, keyCode: 10 ('Space')
> | Resolving ctrl+shift+[Space]
> \ From 21 keybinding entries, matched chord, when: no when condition, source: user.
> + Ignoring single modifier ctrl due to it being pressed together with other keys.
> / Received  keydown event - modifiers: [], code: KeyS, keyCode: 83, key: s
> | Converted keydown event - modifiers: [], code: KeyS, keyCode: 49 ('S')
> | Resolving [KeyS] chorded from ctrl+shift+[Space]
> \ From 1 keybinding entries, matched workbench.action.files.saveFiles, when: no when condition, source: user.

NOTE: "I removed the timestamps from the beggening of the lines to make them shorter."

Solution 2:[2]

The issue might be due to some other extension. In my case, this issue was resolved by removing the "Dependency Analytics" extension. Due to this extension, *.ipynb files were picking CVE as cell language mode. I wasn't able to change the cell language mode to Python without removing the extension. Upon removing, the extension, *.ipynb files showed Python as cell language mode and this resolved issues with key bindings as well as with syntax highlighting.

Note: Cell language is the small text that comes on the bottom right of each cell in a ipynb file. This should be Python for key bindings and syntax highlighting to work properly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 j D3V
Solution 2 Akul Rastogi