Jupyter Notebook Keyboard Shortcuts
Jupyter's shortcut system is genuinely unlike most editors because it's modal, borrowing a concept familiar to Vim users: Command mode (cell selected but not being typed into, indicated by a blue left border) uses single unmodified letters as shortcuts, while Edit mode (actively typing inside a cell, green border) requires modifier keys since letters need to type normally. This split confuses newcomers constantly — pressing 'A' expecting to type the letter but instead inserting a new cell above is a rite of passage for anyone new to notebooks. Once internalized, though, it's a genuinely fast system, particularly for the cell-reordering and cell-type-switching operations that would otherwise require menu clicks. These shortcuts are consistent across Windows, Mac, and Linux since it runs entirely in the browser, aside from the standard Ctrl/Cmd modifier swap. Merging and multi-selecting cells matter most during the messier, exploratory phase of notebook-based work, when a train of thought originally split across several small cells often benefits from being consolidated into fewer, cleaner cells once the exploration settles into something worth keeping. The three natural groupings covered here — Command mode's structural cell operations, Edit mode's text-editing behavior, and the three distinct cell-execution shortcuts — reflect how a typical notebook session actually moves between writing code, running it, and reorganizing the resulting cells.
Command Mode
| Action | Windows | Mac | Description |
|---|---|---|---|
| Insert cell above | A (Command mode) | A | Inserts a new empty cell directly above the currently selected one, only functional in Command mode — pressing A while actively editing text inside a cell just types the letter A instead. |
| Insert cell below | B (Command mode) | B | Inserts a new empty cell directly below the currently selected one, the far more commonly used of the two insert directions since most workflows build downward. |
| Delete selected cell | D, D (press twice) | D, D | Deletes the currently selected cell, requiring the D key pressed twice in quick succession as a deliberate guard against accidental single-keystroke deletion of cell content. |
| Convert cell to Markdown | M (Command mode) | M | Changes the currently selected cell's type from code to Markdown, letting it render formatted text, headings, and links instead of being executed as code. |
| Convert cell to Code | Y (Command mode) | Y | Changes the currently selected cell's type back to Code, the reverse of converting to Markdown. |
| Copy selected cell | C (Command mode) | C | Copies the entire selected cell (code and output) to Jupyter's internal clipboard, separate from the OS clipboard, for pasting elsewhere in the notebook with V. |
| Extend cell selection up/down | Shift+J / Shift+K (Command mode) | Shift+J / Shift+K | Extends the current cell selection to include the next or previous cell as well, letting you select several adjacent cells at once for a bulk action like deleting or moving them together. |
| Merge selected cells | Shift+M (Command mode) | Shift+M | Combines the currently selected cells (extended via Shift+J/K) into a single cell, concatenating their content, useful for consolidating what was originally split across several small cells during exploratory work. |
| Undo last cell operation | Z (Command mode) | Z | Undoes the most recent cell-level operation (like an accidental delete), distinct from Ctrl+Z inside Edit mode which undoes text-editing changes within a cell rather than structural cell operations. |
| Move selected cell up | Ctrl+Shift+Up (or use the toolbar arrow icon) | — | Relocates the currently selected cell one position earlier in the notebook, reordering it without needing to cut and paste its content into a new location manually. |
Edit Mode
| Action | Windows | Mac | Description |
|---|---|---|---|
| Enter Edit mode | Enter (Command mode) | Return | Switches from Command mode into Edit mode on the selected cell, placing a text cursor inside it and changing the border color from blue to green as a visual indicator of the mode switch. |
| Exit Edit mode | Esc | Esc | Returns from Edit mode back to Command mode without executing the cell, the key most new users reach for reflexively once they understand the modal system exists. |
| Open Find and Replace | F (Command mode) | F | Opens a find-and-replace dialog scoped to the current notebook, letting you search across cell content for a specific string and optionally replace it, useful for renaming a variable used across many cells. |
| Indent selected code | Ctrl+] (Edit mode) | Cmd+] | Indents the currently selected lines of code one level, standard for adjusting a block's nesting inside a loop or conditional without retyping the whole block. |
| Toggle comment on selected lines | Ctrl+/ | Cmd+/ | Adds or removes a leading # comment marker on every currently selected line simultaneously, letting you switch off a whole block of code with one keystroke rather than deleting and later retyping it. |
Cell Execution
| Action | Windows | Mac | Description |
|---|---|---|---|
| Run cell, select next | Shift+Enter | Shift+Return | Executes the current cell's code and moves selection to the next cell (creating a new one if it's the last cell in the notebook), the most commonly used execution shortcut for working through a notebook sequentially. |
| Run cell, insert below | Alt+Enter | Option+Return | Executes the current cell and immediately inserts a new empty cell directly below it, useful when iterating and you know you'll want another cell right after this one regardless of what currently follows. |
| Run cell, stay selected | Ctrl+Enter | Cmd+Return | Executes the current cell but keeps that same cell selected afterward rather than advancing, useful for repeatedly re-running one cell (like a plotting cell) while tweaking its code between runs. |
| Interrupt the running kernel | I, I (Command mode, press twice) | I, I | Stops a currently executing cell mid-run, essential when a cell is stuck in an infinite loop or taking far longer than expected and needs to be halted without restarting the entire kernel and losing all defined variables. |
| Restart the kernel | 0, 0 (Command mode, press zero twice) | 0, 0 | Restarts the Python (or other language) process entirely, clearing all defined variables and requiring every cell to be re-run from scratch — the standard fix for a kernel stuck in a bad state, distinct from Interrupt which only stops the current cell. |
Frequently Asked Questions
Why does pressing D once do nothing, but pressing it twice deletes the cell?
Delete Cell is deliberately bound to a double-tap (D, D in quick succession) rather than a single keystroke, specifically as a safeguard against accidentally deleting a cell's content with one stray keypress while in Command mode. A single D press does nothing by itself and waits briefly for a second D before triggering the delete.
How do I tell whether I'm in Command mode or Edit mode without testing a shortcut?
Jupyter shows this visually with the selected cell's left border color — a blue border means Command mode (single letters act as shortcuts), while a green border means Edit mode (you're typing directly into the cell and need modifier-key shortcuts). Glancing at that border color before pressing a single-letter shortcut avoids the common mistake of accidentally typing a letter into your code instead of triggering the intended action.
What's the actual difference between the three 'run cell' shortcuts?
All three execute the current cell's code identically — they differ only in what happens to selection afterward. Shift+Enter moves to (or creates) the next cell, Alt+Enter always inserts and selects a brand new cell directly below regardless of what already follows, and Ctrl+Enter (Cmd+Return on Mac) keeps the same cell selected, which is the one to use when you're iterating repeatedly on a single cell like a data visualization.
Why does pressing a letter key sometimes run a command instead of typing into a cell?
Jupyter notebooks have two distinct input modes just like Vim does: Command mode (blue cell border) treats letter keys as commands — pressing a converts the current cell to Markdown, b inserts a cell below, dd deletes the selected cell — while Edit mode (green cell border, entered by pressing Enter or clicking into a cell) treats the same keys as literal typed text. Forgetting which mode you're in is the single most common source of confusion for people new to notebooks, since pressing dd in Edit mode just types the letter d twice into your code rather than deleting anything.
What's the difference between Interrupt and Restart, and when should I use each?
Interrupt (I, I) stops only the currently running cell, leaving every previously defined variable and import intact — the right choice when one specific cell is stuck or taking too long. Restart (0, 0) wipes the entire kernel process clean, losing every variable and requiring the whole notebook to be re-run from the top — necessary when the kernel itself is in a genuinely broken state that Interrupt alone can't fix, such as memory corruption or a hung C extension that Interrupt can't reach.
Is there a way to restart the kernel and rerun every cell from the top in one action?
The Kernel menu's 'Restart & Run All' option does exactly this, clearing all variables and outputs, restarting the process fresh, and then executing every cell in order from top to bottom — the standard sanity check before considering a notebook finished, since it catches any cell that only worked because of leftover state from a cell you ran out of order earlier, a common way notebooks silently develop hidden execution-order dependencies invisible until you actually restart clean.
What's the difference between Z in Command mode and Ctrl+Z while typing in a cell?
Z pressed in Command mode undoes structural cell-level operations, like restoring a cell you just deleted, while Ctrl+Z (or Cmd+Z) used inside Edit mode while actively typing undoes ordinary text-editing changes within that specific cell's content — they operate on two different undo histories, one for cell structure and one for text content.