February 17, 2023 · tutorial

Fly through Jupyter with keyboard shortcuts 🚀

If you spend a lot of time in Jupyter Notebook, the easiest way to increase your productivity is by using the built-in keyboard shortcuts.

Unlike most applications, Jupyter's keyboard shortcuts are easy to remember since they often only require a single key.

Below, I'll cover the 25 most useful keyboard shortcuts (including some hidden gems 💎) so that you can speed up your workflow today!

Here's what I'll cover:

I'm focusing on Jupyter Notebook in this post, but I've made a note of any differences for JupyterLab.

Command and Edit Modes 🎛

Before we begin, it's critical that you're aware of the difference between Command Mode and Edit Mode, since different shortcuts work for each mode.

In Command Mode, there's a gray border with a blue bar, whereas in Edit Mode, there's a blinking cursor and a green border:

Command and Edit modes

How to switch modes:

Note: JupyterLab uses a blue border for Edit Mode.

Most important shortcuts ⭐

Here are the keyboard shortcuts you should learn first, because you'll use these the most:

Command Mode:

You can use dd (meaning d twice) to delete cells, but I just use x instead.

Edit Mode:

You can also use standard text editor keyboard shortcuts for cut, copy, and paste.

Either Mode:

Power user shortcuts 💪

These shortcuts are not as well-known, but will help you to become a true power user:

Command Mode:

p: Open the command palette. You can scroll or search through commands, then select an action and hit Enter to run it.

JupyterLab: Cmd+Shift+c (Mac), Ctrl+Shift+c (Windows)

Command palette

o: Toggle between hiding and showing the output for selected code cells. This is useful when the output is taking up too much of your screen.

JupyterLab: This shortcut is not available. Instead, open the command palette and search for "Collapse Selected Outputs."

Toggle cell output

z: Undo cell deletion. You can undo multiple deletions, and each cell will go back to its original position. It works even if you have done other work since the deletions!

Undo cell deletion

Edit Mode:

Cmd+/ (Mac), Ctrl+/ (Windows): Toggle between commented and uncommented code. You can apply this to multiple lines at once by first selecting those lines.

Toggle comments

Shift+Tab: View the docstring for a function. Hit Shift+Tab three more times to open the docstring in a new pane.

JupyterLab: Hit Shift+Tab once.

View docstring

Multiple cursors: Hold down Option (Mac) or Alt (Windows), then click your mouse and drag up or down. This allows you to edit multiple lines at once.

Alternatively, you can hold down Cmd (Mac) or Ctrl (Windows) and click where you want to create new cursors. This is useful if you want to create multiple cursors that are not adjacent to one another.

Multiple cursors

What did I miss? Let me know your favorite Jupyter keyboard shortcuts in the comments below! 👇

Comments powered by Disqus