'How can I block comment code in an IPython notebook with a German keyboard?

How can I block comment a selected text in an IPython Notebook with a German keyboard layout? Ctrl-/ does not work, which on a German keyboard actually is Ctrl-Shift-7.



Solution 1:[1]

I found this great workaround for international keyboard layouts from Dataman in How do I comment out multiple lines in Jupyter Ipython notebook?

Press the Alt button and keep holding it. The cursor should change its shape into a big plus sign. The next step is, using your mouse, to point to the beginning of the first line you want to comment and while holding the Alt button pull down your mouse until the last line you want to comment. Finally, you can release the Alt button and then use the # character to comment.

Solution 2:[2]

You can define custom keyboard shortcuts in custom.js. For Jupyter this file is located in .jupyter/custom/. On a German keyboard layout I use Ctrl + , as a shortcut to comment by adding this to custom.js:

define([
    'base/js/namespace',
    'base/js/events'
    ],
    function(IPython, events) {
        events.on("app_initialized.NotebookApp",
            function () {
                IPython.Cell.options_default.cm_config.extraKeys = {"Ctrl-," : "toggleComment"};
            }
        );
    }
);

Solution 3:[3]

I used it with nbextensions. Install it. See docs here

Then, in your nbconfig.

enter image description here

Just configure it with your personal preference. I am using german keyboard and used this implementation successfully for months.

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 Robbotnik
Solution 2 Fabian Rost
Solution 3 Createdd