In a code cell in the Jupyter notebook, line numbers may be turned on by typing ESC-L.
The easiest way to add line numbers to a Jupyter Notebook is to use the keyboard shortcut, which is Ctrl-m to enter Command Mode, then type L. Just highlight the cell you are interested in adding line numbers to, then hit the keyboard shortcut to toggle the line numbers.
In VS Code Jupyter Notebook, you can toggle line numbers by pressing L.
CTRL - ML toggles line numbers in the CodeMirror area. See the QuickHelp for other keyboard shortcuts.
In more details CTRL - M (or ESC) bring you to command mode, then pressing the L keys should toggle the visibility of current cell line numbers. In more recent notebook versions Shift-L should toggle for all cells.
If you can't remember the shortcut, bring up the command palette Ctrl-Shift+P (Cmd+Shift+P on Mac), and search for "line numbers"), it should allow to toggle and show you the shortcut.
On IPython 2.2.0, just typing l (lowercase L) on command mode (activated by typing Esc) works. See [Help] - [Keyboard Shortcuts] for other shortcuts.
Also, you can set default behavior to display line numbers by editing custom.js
.
Select the Toggle Line Number Option from the View -> Toggle Line Number.
To turn line numbers on by default in all cells at startup I recommend this link. I quote:
Navigate to your jupyter config directory, which you can find by typing the following at the command line:
jupyter --config-dir
From there, open or create the
custom
folder.In that folder, you should find a
custom.js
file. If there isn’t one, you should be able to create one. Open it in a text editor and add this code:define([ 'base/js/namespace', 'base/js/events' ], function(IPython, events) { events.on("app_initialized.NotebookApp", function () { IPython.Cell.options_default.cm_config.lineNumbers = 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