marimo Basics
On this page
Every key and menu on this page was read out of marimo 0.24.2, the version this course installs. Press Ctrl+Shift+H inside a notebook to see the full list at any time, and Ctrl+K to search every command by name.
Ctrl throughout. On macOS use Cmd instead, except where a line says otherwise.
Running a cell#
| What you want | Press |
|---|---|
| Run this cell and stay in it | Ctrl+Enter |
| Run this cell and move to the next one | Shift+Enter |
| A new empty cell below this one | Ctrl+Shift+P |
| A new empty cell above this one | Ctrl+Shift+O |
Shift+Enter makes a new cell only when there is nothing below. In the middle of a notebook it moves to the cell that is already there. To run a cell and then write a new one under it, use Ctrl+Enter and then Ctrl+Shift+P.
You never have to run the cells that depend on the one you changed. marimo works out what depends on what and reruns those by itself.
Getting a cell back after you delete it#
Ctrl+Z will not do it. Ctrl+Z undoes typing inside one cell, which is a different thing, so it does nothing for a cell that is no longer there.
Two things will:
- The undo button at the bottom right, which appears when you delete a cell that had something in it. It stays available until you close the notebook, so it is still there several minutes later.
Ctrl+K, then typeundo.
Deleting an empty cell gives you no button, which is why one deletion offers undo and another does not.
Turn off the shortcut that deletes cells. Open the settings gear, go to Keymap, and turn Destructive delete off. It is on by default. With it off, Shift+Backspace stops deleting cells that have code in them, and you delete a cell deliberately from its ⋮ menu instead. This is worth doing before you start experimenting with a notebook.
The safest habit is still to commit before you try something. Git restores a whole file; undo restores one cell.
Clearing what a cell printed#
From a cell's ⋮ menu, Clear output empties that one. Clear all outputs empties the notebook. In code, mo.output.clear() does the same for the cell it runs in.
You rarely need either. A cell's output is whatever its last line evaluated to, so running the cell again replaces it.
Fitting more on the screen#
Ctrl+.hides every cell's code and leaves the text and the outputs. Press it again to bring the code back.Ctrl+Shift+\** collapses every section, and **Ctrl+Shift+/expands them again. Sections come from the markdown headings.- A cell's ⋮ menu has Config → Set cell output area: above, which puts that cell's result above its code instead of below.
Formatting on save#
marimo can tidy your code every time it saves the notebook: spacing, quotes, and the order of your imports. Turn it on once.
- Click the settings gear in the notebook page, then Editor in the list on the left.
- Under the heading FORMATTING, tick Format on save. Line length, beside it, can stay at 79.
The formatter is called ruff, and it arrives with the marimo[recommended] install in Your AI Tools and Babson Key. Without it, marimo says To enable code formatting, please install ruff. To check the setting, run uv run marimo config show in the terminal; it prints format_on_save = true under [save].
Your notebooks are .py files in git, and a diff is how both of us see what changed between two commits. Code formatted the same way every time gives a diff of the lines you actually changed. Code formatted differently each time buries that change among shifted spaces. Much of your code will come from your agent, and this setting makes all of it look as if one person wrote it.
When a cell will not run#
| What you see | What it means |
|---|---|
Variable 'x' is defined in multiple cells |
A name lives in exactly one cell here. Rename yours, or put your code in the cell that already defines it |
| A cell greyed out, with no output | Something it depends on was deleted or has not run. Look further up |
error: Failed to spawn: marimo |
Run uv add marimo. If that answers No pyproject.toml found, your Terminal is outside your project: open VS Code from GitHub Desktop and use a new Terminal there |
uv trampoline failed to canonicalize script path |
The virtual environment is broken. Delete the .venv folder in your repository, then run uv add "marimo[recommended]" |
What does not go on GitHub#
marimo writes every cell's output into a __marimo__ folder beside your notebook. Your .py file stays clean because of it, which is the reason this course uses marimo rather than Jupyter, and that only holds while the folder stays out of your repository. The .gitignore from step 11 of Getting Started covers it.
Last updated: Tuesday, 11/3/2026