How to enable line wrapping in ipython notebook

前端 未结 3 1028
青春惊慌失措
青春惊慌失措 2021-02-05 09:36

I have been trying to enable line wrapping in ipython notebook. I googled it with no results and i typed ipython notebook --help in a terminal. This gives me a ton of configurat

3条回答
  •  时光说笑
    2021-02-05 10:05

    As @Matt pointed out you have to configure CodeMirror to enable wrapping.

    However, this can be achieved by simply adding the following line to your custom.js:

     IPython.Cell.options_default.cm_config.lineWrapping = true;
    

    So there is no need to loop through all the cells. In a similar fashion you can enable line numbers, set the indentation depth and so on (see the link posted by @Matt for other options). The location of your custom.js depends on your OS (on my Ubuntu machine it is ~/.ipython/profile_default/static/custom).

    Update:

    In IPython 3 the plain call does not work any more, thus it is required to place the setting within an appropriate event handler. A possible solution could look like:

    define([
        'base/js/namespace',
        'base/js/events'
        ],
        function(IPython, events) {
            events.on("app_initialized.NotebookApp",
                function () {
                    IPython.Cell.options_default.cm_config.lineWrapping = true;
                }
            );
        }
    );
    

提交回复
热议问题