Most useful keyboard shortcuts for Notebook & Lab

Hi all! I wrote about blog post about Jupyter’s most useful keyboard shortcuts. I focused on Jupyter Notebook in the post, but I noted any differences for JupyterLab.

I thought it might be of interest to some of you on the forum, so I copied the post below.

Enjoy!


Fly through Jupyter with keyboard shortcuts :rocket:

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 :gem:) so that you can speed up your workflow today!

Here’s what I’ll cover:

  • Command and Edit Modes
  • Most important shortcuts
  • Power user shortcuts

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


Command and Edit Modes :control_knobs:

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:

How to switch modes:

  • Esc: Switch to Command Mode
  • Enter: Switch to Edit Mode

Note: JupyterLab uses a blue border for Edit Mode.


Most important shortcuts :star:

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

Command Mode:

  • up / down arrows: Navigate up and down
  • a / b: Create a cell above (a) or below (b) the current cell
  • m / y: Change the cell type to Markdown (m) or code (y)
  • Shift+up or Shift+down: Select multiple cells
  • Shift+m: Merge cells
  • x / c / v: Cut (x), copy (c), or paste (v) cells
  • s: Save the notebook
    • JupyterLab: Cmd+s (Mac), Ctrl+s (Windows)
  • h: Show all keyboard shortcuts
    • JupyterLab: not available

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

Edit Mode:

  • Ctrl+Shift+-: Split the current cell at the cursor
  • Cmd+z (Mac), Ctrl+z (Windows): Undo text edits or deletions
  • Tab: Code completion (when writing code) or indent (at the start of a line)

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

Either Mode:

  • Cmd+Enter (Mac), Ctrl+Enter (Windows): Run the selected cell
  • Shift+Enter: Run the selected cell and move to the cell below

Power user shortcuts :muscle:

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)

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.”

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!

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.

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.

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.

What did I miss? Let me know your favorite Jupyter keyboard shortcuts below! :point_down:

5 Likes

Hi,
Command Mode is fantastic! Thank you.
Is it possible to assign keys for Run All?

Great question! I haven’t done it myself, but here are instructions for adding keyboard shortcuts in Jupyter Notebook and JupyterLab.

1 Like

Hi Kevin,
Those options in the links are not available anymore.
Settings has its rigid structure and nowhere to write the command script.
Thanks anyway.

They are available, just click “JSON Settings Editor”:

or from command palette:

image

2 Likes

exactly :vulcan_salute:t4:
thank you