Tuesday Tip #3: Fly through Jupyter with keyboard shortcuts πŸš€


Hi Reader,

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 most useful keyboard shortcuts (including some hidden gems πŸ’Ž) so that you can speed up your workflow today!

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


Command Mode and Edit Mode

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 Edit Mode, there's a blinking cursor and a green border, whereas in Command Mode, there's a gray border with a blue bar:

To change modes:

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

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:

  • 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 on Mac, Ctrl+s on 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+dash: Split the current cell at the cursor

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

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.

Multi-cursor support: 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.

How helpful was today’s tip?

β€‹πŸ€©β€‹πŸ™‚β€‹πŸ˜β€‹


If you enjoyed this issue, please forward it to a friend! Takes only a few seconds, and it really helps me out πŸ™

See you next Tuesday!

- Kevin

P.S. Did someone awesome forward you this email? Sign up here to receive data science tips every week!

Learn Data Science from Data School πŸ“Š

Join 25,000+ aspiring Data Scientists and receive Python & Data Science tips every Tuesday!

Read more from Learn Data Science from Data School πŸ“Š

Hi Reader, Regardless of whether you enrolled, thanks for sticking with me through the launch of my new course! πŸš€ I've already started exploring topics for the next course... πŸ˜„ πŸ”— Link of the week git cheat sheet (PDF) A well-organized and highly readable cheat sheet from Julia Evans, the brilliant mind behind Wizard Zines! πŸ‘‰ Tip #48: Three ways to set your environment variables in Python I was playing around with Mistral LLM this weekend (via LangChain in Python), and I needed to set an...

Hi Reader, Last week, I announced that a new course is coming soon and invited you to guess the topic. Hundreds of guesses were submitted, and four people who guessed correctly got the course for free! (I've already notified the winners.) I'll tell you about the course next week. In the meantime, I've got a new Tuesday Tip for you! πŸ‘‡ πŸ”— Link of the week OpenAI just unleashed an alien of extraordinary ability (Understanding AI) If you're curious about what makes OpenAI's new "o1" models so...

Hi Reader, I'm really proud of this week's tip because it covers a topic (data leakage) that took me years to fully understand. 🧠 It's one of those times when I feel like I'm truly contributing to the collective wisdom by distilling complex ideas into an approachable format. πŸ’‘ You can read the tip below πŸ‘‡ or on my blog. πŸ”— Link of the week Building an AI Coach to Help Tame My Monkey Mind (Eugene Yan) In this short post, Eugene describes his experiences calling an LLM on the phone for coaching:...