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 configuration commands for a config file, but no line wrapping. Does anyone know if ipnotebook has this feature and if so how to enable it? Your help would be greatly appreciated. Thank you.
Enable row numbers via hotkeys You can enable row numbers in all code cells by pressing Shift + L while no cell is active. If you cannot remember these hotkeys, open the command palette by pressing Control + Shift + P and search for 'line numbers'.
In a code cell in the Jupyter notebook, line numbers may be turned on by typing ESC-L.
If you would like to display some code or text in an indented block, all you have to do is to start the line with a > followed by a space and then the text. The text is indented and has a gray horizontal line to the left until the next carriage return is detected.
IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. from __future__ import print_function import sys. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.
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
).
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;
}
);
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With