Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 39 ยท Getting Started

Modes and Keyboard Shortcuts

Learn Jupyter's two modes, command and edit, the most useful keyboard shortcuts for cells and editing, the command palette, and how to customize shortcuts.

Reaching for the mouse for every action makes notebooks slow. Jupyter solves this with a modal interface, similar to editors such as Vim: the same key does different things depending on the mode you are in. Once you know the two modes and a dozen shortcuts, you can build a notebook almost without touching the mouse.

Shortcuts below are for current JupyterLab and Jupyter Notebook 7 on Windows and Linux. On macOS replace Ctrl with Cmd where the text says so. Check Help โ†’ Show Keyboard Shortcuts (or the Settings โ†’ Advanced Settings Editor โ†’ Keyboard Shortcuts panel in JupyterLab) for the exact list in your version. We practise the logic with a small Python stand-in because Jupyter itself cannot run here.

The two modes

Command mode Edit mode
Meaning You act on cells You type inside a cell
How to enter Press Esc (or click left of the cell) Press Enter (or click inside the cell)
What it looks like Cell selected, blue bar; no cursor Cursor blinks in the editor; green bar in older versions
Typical keys A, B, D D, M, Y, Z, arrows Normal typing, Tab completion, Ctrl+/

If you press a letter and your cell is deleted or turns into Markdown, you were in command mode when you thought you were in edit mode. Press Esc then Z to undo a cell deletion.

stateDiagram-v2
    [*] --> Command
    Command --> Edit: Enter
    Edit --> Command: Esc
    Edit --> Edit: Shift+Enter runs and moves on
    Command --> Command: A B D M Y arrows

Esc and Enter switch the mode; the keys you press mean different things in each.

Shortcuts you need every day

In both modes

Shortcut Action
Shift+Enter Run cell, select next
Ctrl+Enter Run cell, stay
Alt+Enter Run cell, insert below
Ctrl+S Save notebook

In command mode

Key Action
โ†‘ / โ†“ or K / J Select previous or next cell
A / B Insert cell above or below
D D (press D twice) Delete selected cell
Z Undo cell deletion
M / Y Change cell to Markdown / code
C / X / V Copy, cut, paste cell
Shift+M Merge selected cell with the next one
0 0 (press 0 twice) Restart the kernel (a confirmation dialog appears)
I I (press I twice) Interrupt the kernel
Shift+โ†‘ / โ†“ Extend selection to several cells
Enter Switch to edit mode
H Show the shortcut help (classic)

In edit mode

Shortcut Action
Tab Code completion, or indent when at the start of a line
Shift+Tab Show documentation (tooltip) for the name under the cursor
Ctrl+/ Comment or uncomment the selected lines
Ctrl+Z / Ctrl+Y Undo / redo text typing
Ctrl+Shift+- Split cell at cursor
Esc Go back to command mode

Shift+Tab is a lifesaver: put the cursor inside the parentheses of a function call and press it to read the function's signature and docstring without leaving the notebook. Press ? after a name, as in len?, for a longer help pane (see Magics).

Code completion and help

In a code cell, type the first letters of a name and press Tab. The kernel proposes completions: variable names, imported modules, methods of an object after a dot (for example after my_list. press Tab to see all list methods), even file paths inside strings. Completion is asked of the kernel, so it knows about the objects that really exist in memory, which a normal code editor cannot do.

The command palette

Remember only one shortcut and you can still find everything: the command palette (Ctrl+Shift+C in JupyterLab, or Ctrl+Shift+F in Notebook 7). Start typing an action's name ("restart", "merge", "toggle line numbers") and choose from the list. It shows the shortcut next to each command, so it is also a great way to learn shortcuts over time.

Customizing shortcuts

JupyterLab lets you change shortcuts in Settings โ†’ Settings Editor โ†’ Keyboard Shortcuts. The settings are stored as JSON. A user override looks like this (read-only):

JSON
{
  "shortcuts": [
    {
      "command": "notebook:run-cell-and-select-next",
      "keys": ["Ctrl J"],
      "selector": ".jp-Notebook:focus"
    }
  ]
}

The selector limits the shortcut to the notebook, so it will not clash with another panel. Do not rebind too many keys: shortcuts that differ from the standard ones make it harder to use someone else's computer, or to follow tutorials.

Practice with a stand-in

The following stand-in models command mode: a tiny interpreter that reads a string of key presses and edits a list of cells. Try changing keys to see how a sequence of shortcuts builds a notebook:

Python Stand-in: a command-mode key interpreter

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The second stand-in prints a cheat sheet and checks you against it. Handy for self-testing:

Python Stand-in: shortcut flash cards

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Habits that save time

  • Run a cell with Shift+Enter without thinking about it; go to the Run menu only for "Run all above".
  • Learn A, B, D D, M, Y first. They cover most cell management.
  • Use Tab and Shift+Tab constantly: they replace many trips to documentation.
  • If a key does something strange, check your mode first.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. You want to delete a whole cell with the keyboard. Which mode must you be in, and what do you press?

    Cell-level actions work in command mode. D D (press D twice) deletes the selected cell, and Z undoes it.
  2. 2. What does Shift+Tab do inside the parentheses of a function call in edit mode?

    Shift+Tab asks the kernel for the signature and docstring of the object at the cursor.
  3. 3. Which key leaves edit mode and returns to command mode?

    Esc returns to command mode; Enter enters edit mode on the selected cell.
  4. 4. Where do you find any action by name if you forget its shortcut?

    The command palette lists every action with its shortcut and lets you search by name.

Summary

  • Jupyter is modal: Esc enters command mode (act on cells), Enter enters edit mode (type in a cell).
  • Shift+Enter, Ctrl+Enter and Alt+Enter run cells in three slightly different ways.
  • In command mode: A, B, D D, Z, M, Y, C, X, V and Shift+M manage cells.
  • Tab completes and Shift+Tab shows documentation, because the kernel answers both.
  • The command palette finds any action by name, and shortcuts can be customised in JSON.

Next: Kernels explained