Re-posted from: http://randyzwitch.com/line-numbers-ipython-notebook/
Lately, I’ve been using IPython Notebooks for all of my Python and Julia coding. The ability to develop and submit small snippets of code and create plots inline is just so useful that it has broken the stranglehold of using an IDE while I’m coding. However, the one thing that was missing for a smooth transition was line numbers in the cells; luckily, this can be achieved in two ways.
The easiest way to add line numbers to an IPython Notebook is to use the keyboard shortcut, which is ctrl-m-l. Just highlight the cell you are interested in adding line numbers to, then hit the keyboard shortcut to toggle the line numbers.
Add Line Numbers to All Cells at Startup
While the keyboard shortcut is great for toggling line numbers on/off, I prefer having line numbers always on. Luckily, the IPython Dev folks on Twitter were kind enough to explain how to do this:
@randyzwitch add `IPython.Cell.options_default.cm_config.lineNumbers = true;` to your custom.js
— IPython Dev (@IPythonDev) October 28, 2013
I use OSX with the default ‘profile_default’ profile, so the path for my custom.js file for IPython is:
Similarly, you can do the same for IJulia: