13

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.

SmCaterpillar
  • 6,683
  • 7
  • 42
  • 70

6 Answers6

13

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.

Robbotnik
  • 557
  • 8
  • 8
2

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.

Createdd
  • 865
  • 11
  • 15
  • Is there an equivalent solution for Jupyterlab? – Mark P Dec 15 '22 at 07:23
  • 1
    I didn't find a Jupyterlab solution so far. And this is one of the reasons I still use Jupyter Notebook – Createdd Dec 16 '22 at 10:07
  • @Createdd I searched for months for a decent solution for this problem. I bought a new keyboard without numpad and in jupyterlab ONLY "Ctrl" together with the division sign on the numpad worked for comment/uncomment (German layout). I still don't figured out how to change the bindings BUT I just found out that it also depends on the browser which is used. Mozilla is my default browser, when I started jupyterlab in chrome, suddenly "Ctrl+#" works too (the other binding on the numpad still works). Just wanted to let you know. I just use lab in chrome now, which is fine for me. – Rabinzel Jan 17 '23 at 17:25
0

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"};
            }
        );
    }
);
Fabian Rost
  • 2,284
  • 2
  • 15
  • 27
  • 4
    This did not work for me (after restarting Jupyter) using Jupyter Notebook 5 under OS X 10.11 – AdamAL Sep 07 '17 at 06:03
0

Well after trying every combination with ctrl, voilà, ctrl-# does the job.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
0

On a Nordic keybord (and I think this goes for German as well) simply hit Ctrl+Shift+7 (=Ctrl+/)

Emil Lykke Jensen
  • 389
  • 1
  • 3
  • 18
0

I found a comment by AlexanderMelde on GitHub which helped me out that is worked for me:

Strg + /

using the devide key from the numpad instead of the one with the "7" works for me with German keyboard layout.

Hope it also works for you!

F K
  • 1
  • 1