JupyterLab Keyboard Shortcuts: A Comprehensive Guide

One of the most powerful features of JupyterLab is its extensive set of keyboard shortcuts, which can greatly speed up your workflow and increase your productivity. In this post, we’ll provide a comprehensive guide to JupyterLab keyboard shortcuts, including some lesser-known ones that you may find particularly useful.

JupyterLab Keyboard Shortcuts: A Comprehensive Guide

As a data scientist, you’re likely familiar with JupyterLab, the popular open-source web-based interactive development environment (IDE) for working with data. One of the most powerful features of JupyterLab is its extensive set of keyboard shortcuts, which can greatly speed up your workflow and increase your productivity. In this post, we’ll provide a comprehensive guide to JupyterLab keyboard shortcuts, including some lesser-known ones that you may find particularly useful.

Getting Started with Keyboard Shortcuts

Before we dive into the specific keyboard shortcuts, it’s important to know how to activate them. By default, JupyterLab has two modes: command mode and edit mode. In command mode, you can navigate around your notebook using keyboard shortcuts, while in edit mode, you can edit cells as you would in a normal text editor. You can switch between these modes using the Esc and Enter keys, respectively.

Once you’re in command mode, you can access a list of all available keyboard shortcuts by pressing the H key. This will open a help dialog that lists all of the available shortcuts, organized by category. You can use the arrow keys to navigate through the list, and press Esc to close the dialog.

Basic Editing Shortcuts

Let’s start with some basic editing shortcuts that you’ll use frequently when working with JupyterLab:

Ctrl + Enter: Run the current cell Shift + Enter: Run the current cell and move to the next cell Alt + Enter: Run the current cell and insert a new cell below Esc: Switch to command mode Enter: Switch to edit mode Tab: Indent selected text or autocomplete code Shift + Tab: Show documentation or function signature Ctrl + Z: Undo last action Ctrl + Shift + Z: Redo last action Ctrl + /: Comment or uncomment selected lines

These shortcuts should feel familiar if you’ve used other text editors or IDEs before. The Ctrl + Enter shortcut is particularly useful for quickly running code in a cell, while Shift + Enter is great for quickly iterating through cells.

Next up, let’s look at some navigation shortcuts that will help you move around your notebook more quickly:

Up and Down arrows: Move up or down one cell at a time J and K: Move down or up one cell at a time A and B: Insert a new cell above or below the current cell X: Cut the current cell C: Copy the current cell V: Paste the cut or copied cell below the current cell Z: Undo cell deletion Shift + M: Merge selected cells Shift + J or Shift + Down: Extend the selection down one cell Shift + K or Shift + Up: Extend the selection up one cell Shift + A or Shift + B: Insert a new cell above or below the current cell and enter edit mode Shift + L: Toggle line numbers for all cells

These shortcuts are essential for quickly navigating your notebook and manipulating cells. The A and B shortcuts for inserting new cells are particularly useful, as is the Shift + M shortcut for merging cells.

Cell Type Shortcuts

JupyterLab supports several different cell types, including code cells, markdown cells, and raw cells. Here are some shortcuts for working with these different cell types:

Y: Change the current cell to a code cell M: Change the current cell to a markdown cell R: Change the current cell to a raw cell 1 through 6: Change the current cell’s heading level (in markdown cells) Shift + Tab: Show documentation or function signature (in code cells) Ctrl + Shift + -: Split the current cell at the cursor position Ctrl + Shift + +: Merge selected cells

These shortcuts are particularly useful when working with markdown cells, as you can quickly change the heading level and format your text. The Shift + Tab shortcut for showing documentation is also very useful when working with code cells.

Miscellaneous Shortcuts

Finally, here are some miscellaneous shortcuts that don’t fit neatly into any of the above categories, but are still very useful:

Ctrl + Shift + F: Search and replace within the current cell Esc + F: Find and replace within the notebook Ctrl + Shift + P: Open the command palette Ctrl + Shift + C: Copy the selected text as a code block Ctrl + Shift + V: Paste the copied text as a code block Ctrl + Shift + O: Toggle the output of the current cell Ctrl + Shift + S: Save the notebook

The Ctrl + Shift + F shortcut for search and replace is particularly useful when working with large notebooks, as is the Ctrl + Shift + P shortcut for opening the command palette.

Conclusion

JupyterLab keyboard shortcuts are an essential tool for any data scientist or developer working with Jupyter notebooks. By learning and using these shortcuts, you can greatly speed up your workflow and increase your productivity. We hope this comprehensive guide has been helpful in getting you started with JupyterLab keyboard shortcuts. Happy coding!