Some neat Jupyter tricks

Dipam Vasani
The Startup
Published in
3 min readJan 6, 2020

This article assumes that you already know basic keyboard shortcuts for Jupyter notebooks. If you don’t, here’s a quick recap. Invest time in learning these and the ones that follow. Don’t use your mouse. It makes you slow.

0. Recap

  • Esc : Toggle between command mode and edit mode
  • A : Insert cell above
  • B : Insert cell below
  • DD : Delete cells
  • C : Copy cells
  • X : Cut cells
  • V : Paste cells
  • Shift + Enter / Return Run cell

1. Restart notebook

If you want to restart your notebook just press ESC + 00 to do so.

2. Scroll your notebook

You can scroll your notebook using Space to scroll down and Shift + Space to scroll back up.

3. Undo cell deletion

If you delete a cell by mistake, you can undo it using ESC + Z

4. Seperate cells

A lot of times, we start by writing code in one cell, and then we want to split parts of it into multiple cells. To do so, simple place the cursor before the line you want to split, and press Control + Shift + -

5. Print Everything

When we print multiple things in Jupyter, it will only print the last thing.

To print everything, copy paste and run these lines on code in your Jupyter notebook.

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

The disadvantage of this would be that some libraries would spit out a lot of outputs. To suppress printing them just put a semi-colon at the end of the lines spitting a lot of output or just undo the above behavior by changing “all” to “last_expr”.

6. Skip a cell from running

There are multiple reasons why you might want to skip cells from running. Instead of commenting it out, deleting it or doing something else, just add a simple

%%script falseLines I don't want to run

at the top of the cell.

7. Jump to current running cell.

Copy paste these lines of code at the top of your notebook, then you can jump to the current running cell using Control + I (You can change this)

%%javascript
// Go to Running cell shortcut
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('Alt-I', {
help : 'Go to Running cell',
help_index : 'zz',
handler : function (event) {
setTimeout(function() {
// Find running cell and click the first one
if ($('.running').length > 0) {
//alert("found running cell");
$('.running')[0].scrollIntoView();
}}, 250);
return false;
}
});

Also checkout:

References:

https://forums.fast.ai/t/jupyter-notebook-enhancements-tips-and-tricks/17064/28

--

--