Jupyter Notebook Cheatsheet

Published: (December 9, 2025 at 01:11 AM EST)
3 min read
Source: Dev.to

Source: Dev.to

Jumpstart the Jupyter Notebook productivity with essential shortcuts, magic commands, and workflow tips that will transform your data science and development experience.

Jupyter Notebook has become the de facto standard for interactive computing, data analysis, and machine learning workflows. Whether you’re working with Python for data science, experimenting with AI models, or prototyping code, mastering Jupyter’s keyboard shortcuts and magic commands can dramatically boost your productivity.

This cheatsheet covers the most essential commands and shortcuts that every Jupyter user should know, from basic cell navigation to advanced magic commands that streamline your workflow. If you’re new to Python development, you might also find our Python Cheatsheet helpful for understanding Python language constructs that work seamlessly within Jupyter cells.

Understanding Command Mode vs Edit Mode

Command Mode (press Esc): Controls cell‑level operations like creating, deleting, and converting cells.
Edit Mode (press Enter): Allows you to edit the content within a cell.

The most important shortcut is pressing H in Command Mode, which displays the complete keyboard shortcuts help dialog.

Essential Command Mode Shortcuts

Cell Navigation and Execution

  • Shift + Enter – Run the current cell and select the cell below.
  • Ctrl + Enter – Run the current cell without moving to the next one.
  • Alt + Enter – Run the current cell and insert a new cell below.

Cell Management

  • A – Insert a new cell above the current cell.
  • B – Insert a new cell below the current cell.
  • D, D – Delete the current cell (press D twice).
  • Z – Undo the last cell deletion.
  • Shift + M – Merge selected cells (select with Shift + J/K).

Cell Type Conversion

  • Y – Convert to Code.
  • M – Convert to Markdown.
  • R – Convert to Raw.
  • 16 – Convert to Heading levels 1‑6.

Kernel Operations

  • I, I – Interrupt the kernel (press I twice).
  • 0, 0 – Restart the kernel (press 0 twice).

Display and Navigation

  • L – Toggle line numbers.
  • O – Toggle cell output visibility.
  • H – Show the keyboard shortcuts help dialog.

Essential Edit Mode Shortcuts

Text Editing

  • Tab – Code completion or indent.
  • Shift + Tab – Show tooltip/documentation for the object under the cursor.
  • Ctrl + ] – Indent selected lines.
  • Ctrl + [ – Dedent selected lines.
  • Ctrl + / – Toggle comment on selected lines.
  • Ctrl + A – Select all text in the cell.
  • Ctrl + Z – Undo.
  • Ctrl + Shift + Z or Ctrl + Y – Redo.
  • Ctrl + Home – Go to cell start.
  • Ctrl + End – Go to cell end.
  • Ctrl + Left / Ctrl + Right – Move cursor one word left/right.

Mode Switching

  • Esc – Switch to Command Mode.

Magic Commands: Supercharge Your Workflow

Magic commands extend Jupyter’s functionality. Line magics start with % and operate on a single line; cell magics start with %% and operate on the whole cell.

Performance Profiling

# Time a single execution
%time sum(range(1000000))

# Time multiple executions with averaging (more accurate)
%timeit sum(range(1000000))

# Time an entire cell
%%time
total = 0
for i in range(1000000):
    total += i

Running External Scripts

%run my_script.py

Useful when you want to keep reusable functions in separate files. Works well with environment managers like uv or venv.

Package Management

!pip install numpy pandas matplotlib
!conda install scipy

The ! prefix runs shell commands directly from a notebook cell.

Visualization

%matplotlib inline

Renders Matplotlib plots inside notebook cells. Use %matplotlib widget for interactive plots in JupyterLab.

File Operations

%%writefile example.py
def hello_world():
    print("Hello, World!")
    return True

Writes the cell content to example.py. You can read files using standard Python I/O or shell commands.

Shell Commands

# Single‑line shell commands
!ls -l
!pwd
!git status

# Multi‑line shell commands
%%bash
echo "Hello from Bash"
ls -l
find . -name "*.py" | head -10

Execute any terminal command without leaving the notebook.

Back to Blog

Related posts

Read more »