How can I block comment code in the IPython notebook?

Default solution

In IPython 2.x and 3.x (cmd|ctrl)-/ works but requires an english (american) keyboard layout, see

Other keyboard layouts

In case you have a non-english keyboard layout, you can define a custom keybinding for the codemirror editor via your custom.js. To this end add e.g. the following lines

    function(IPython, events) {
            function () {
                IPython.Cell.options_default.cm_config.extraKeys = {"Ctrl-," : "toggleComment"};

to use Ctrl+, to toggle (block) comments. I use this with a german keyboard layout and IPython 3.0.
The previous solution (see edits) worked fine with chrome, but not with firefox.

Old solution (IPython 1.x)

If you are using IPython 1.x you can try the comment-uncomment.js from – I haven’t tried this yet, but I guess its a good start.

Leave a Comment