Command mode, edit mode and shortcuts

Jupyter · Essentials · 8 min

A dozen shortcuts make notebook work several times faster than reaching for menus.

Notebooks have two modes, and the same key means different things in each.

Edit mode (cursor in a cell, cell border highlighted for editing): keys type text. Tab completes names, Shift+Tab shows the signature and docstring of the function under the cursor, and Ctrl+/ toggles comments. Press Esc to leave.

Command mode (no cursor, cell selected): keys act on cells. Press Enter to start editing the selected cell.

Running cells works in both modes:

  • Shift+Enter: run and move to the next cell;
  • Ctrl+Enter (Cmd+Enter on macOS): run and stay;
  • Alt+Enter: run and insert a cell below.

Command-mode essentials:

  • A / B: insert a cell above / below;
  • D, D (press twice): delete the cell; Z: undo the deletion;
  • M / Y: turn the cell into Markdown / code;
  • C, X, V: copy, cut, paste cells; Shift+Up/Down selects several;
  • Shift+M: merge selected cells;
  • 0, 0: restart the kernel; I, I: interrupt a running cell.

In JupyterLab, Ctrl+Shift+C (Cmd+Shift+C) opens the command palette, a searchable list of every action with its shortcut, so you can discover the rest. Shortcuts are customizable in Settings > Settings Editor > Keyboard Shortcuts.

A frequent beginner surprise: typing b or m while in command mode changes the notebook instead of typing a letter; check which mode you are in.

Remember

  • Esc enters command mode, Enter enters edit mode
  • Shift+Enter runs and advances; A/B insert cells; D,D deletes; M/Y switch cell type
  • The command palette lists every action and shortcut

Watch out for

  • Typing while in command mode and accidentally deleting or converting cells; press Z to undo a deletion.

Check yourself

  1. You are in command mode and press M. What happens?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: jupyterlab.readthedocs.io/en/stable/user/interface.html