Cell Execution 9
On a Mac, Colab prints most shortcuts as ⌘/Ctrl, meaning Cmd or Ctrl, so the Mac column gives both. Alt is the Option key.
| Action | Windows / Linux | Mac |
|---|---|---|
| Run CellExecutes the focused cell and leaves the focus where it is, so the same cell can be run again. | Ctrl+Enter | Cmd+ReturnorCtrl+Return |
| Run & Select NextExecute cell and move to next | Shift+Enter | Shift+Return |
| Run & Insert BelowExecute cell and create new cell below | Alt+Enter | Option+Return |
| Run SelectionExecutes only what is highlighted, such as a few lines inside a cell, instead of the whole cell. | Ctrl+Shift+Enter | Cmd+Shift+ReturnorCtrl+Shift+Return |
| Run AllExecutes every code cell in the notebook from top to bottom, in order. | Ctrl+F9 | Cmd+F9orCtrl+F9 |
| Run Cells Before CurrentRuns every cell above the focused one. | Ctrl+F8 | Cmd+F8orCtrl+F8 |
| Run Focused Cell and BelowExecutes from the focused cell down to the end of the notebook and leaves the cells above untouched. | Ctrl+F10 | Cmd+F10orCtrl+F10 |
| Interrupt ExecutionStops the code that is currently running. | Ctrl+MthenI | Cmd+MthenIorCtrl+MthenI |
| Restart SessionWipes the runtime state, including every variable and imported module; the code in the cells stays as it is. | Ctrl+Mthen. | Cmd+Mthen.orCtrl+Mthen. |
Cell Management 11
Ctrl + M is a prefix: press Ctrl + M, release it, then press the letter. Colab's list says Ctrl + M can be used as a prefix for multi-key-event shortcuts.
| Action | Windows / Linux | Mac |
|---|---|---|
| Add Code Cell BelowPuts an empty code cell directly under the focused cell, without running anything. | Ctrl+MthenB | Cmd+MthenBorCtrl+MthenB |
| Add Code Cell AboveThe new empty code cell lands immediately before the focused one, which moves down a place. | Ctrl+MthenA | Cmd+MthenAorCtrl+MthenA |
| Delete CellRemoves the focused cell, or every selected cell when several are selected, from the notebook. | Ctrl+MthenD | Cmd+MthenDorCtrl+MthenD |
| Convert to CodeTurns the focused text cell into a code cell, so that its contents can be run. | Ctrl+MthenY | Cmd+MthenYorCtrl+MthenY |
| Convert to TextTurns the focused code cell into a text cell, which renders its contents as Markdown. | Ctrl+MthenM | Cmd+MthenMorCtrl+MthenM |
| Move Cell UpShifts the focused cell, or every selected cell, one position toward the top of the notebook. | Ctrl+MthenK | Cmd+MthenKorCtrl+MthenK |
| Move Cell DownSends the focused cell, or every selected cell, one position further down the notebook. | Ctrl+MthenJ | Cmd+MthenJorCtrl+MthenJ |
| Split Cell at CursorDivides the focused cell in two: the text before the cursor stays, the rest goes into a new cell below. | Ctrl+Mthen- | Cmd+Mthen-orCtrl+Mthen- |
| Open Scratch CellOpens a separate cell for trying out code that runs in the same session but is not saved in the notebook. | Ctrl+Alt+N | Cmd+Option+NorCtrl+Option+N |
| Undo Cell ActionReverses the last cell-level action. | Ctrl+MthenZorCtrl+Shift+Z | Cmd+MthenZorCtrl+MthenZorCmd+Shift+ZorCtrl+Shift+Z |
| Redo Cell ActionReapplies a cell action that was undone. | Ctrl+Shift+Y | Cmd+Shift+YorCtrl+Shift+Y |
Cell Selection 6
Toggle cell selection is Ctrl + Click on Windows and Linux, but only Cmd + Click on a Mac.
| Action | Windows / Linux | Mac |
|---|---|---|
| Select All CellsSelects every cell in the notebook. | Ctrl+Shift+A | Cmd+Shift+AorCtrl+Shift+A |
| Select Focused CellSelects the cell that has focus. | Ctrl+Shift+S | Cmd+Shift+SorCtrl+Shift+S |
| Select Multiple CellsClicking with Shift held selects several cells at once. | Shift+Click | Shift+Click |
| Toggle Cell SelectionClicking a cell while holding Ctrl (Cmd on a Mac) toggles whether it is selected. | Ctrl+Click | Cmd+Click |
| Extend Selection to Next CellEach press takes in one more cell below, building a block that can be moved, copied or deleted together. | Shift+Down | Shift+Down |
| Extend Selection to Previous CellGrows the block of selected cells upward by one cell per press, the mirror of the row above. | Shift+Up | Shift+Up |
Editing 8
The Tab shortcut only applies if automatic code completions are disabled under Settings, for both Autocomplete and Toggle docstring help.
| Action | Windows / Linux | Mac |
|---|---|---|
| Comment Current LineComments out the current line; on a Mac Ctrl + / works as well. | Ctrl+/ | Cmd+/ |
| DedentRemoves one level of indentation from the current line; this shortcut cannot be reassigned in Colab. | Shift+Tab | Shift+Tab |
| AutocompleteShows code completions; Tab works only when automatic completions are turned off. | Ctrl+SpaceorTab | Ctrl+SpaceorOption+EscorTab |
| Toggle Docstring HelpShows or hides the code docstring help; applies only when automatic code completions are turned off. | Tab | Tab |
| Find NextMoves to the next find result. | Ctrl+G | Cmd+GorCtrl+G |
| Find PreviousMoves to the previous find result. | Ctrl+Shift+G | Cmd+Shift+GorCtrl+Shift+G |
| Global Find and ReplaceOpens find and replace across the notebook. | Ctrl+H | Cmd+HorCtrl+H |
| Replace All in CellReplaces every match in the current cell. | Ctrl+Shift+H | Cmd+Shift+HorCtrl+Shift+H |
View and Layout 8
| Action | Windows / Linux | Mac |
|---|---|---|
| Show/Hide OutputCollapses the output area of the focused cell to a placeholder, or expands it again. | Ctrl+MthenO | Cmd+MthenOorCtrl+MthenO |
| Toggle Line NumbersShows or hides the numbers beside each line of code, which helps to find the line an error message names. | Ctrl+MthenL | Cmd+MthenLorCtrl+MthenL |
| Cycle Form ViewSwitches a form cell between showing code and form side by side, form only, or code only. | Ctrl+MthenF | Cmd+MthenForCtrl+MthenF |
| Collapse SectionsFolds the cells under each heading out of sight; with cells selected, only their sections fold. | Ctrl+] | Cmd+]orCtrl+] |
| Expand SectionsReveals the cells hidden under collapsed section headers: every section, or only the selected ones. | Ctrl+[ | Cmd+[orCtrl+[ |
| Toggle Current SectionExpands or collapses the current section. | Ctrl+' | Cmd+'orCtrl+' |
| Start SlideshowPresents the notebook as a slideshow; the row below is the variant that always opens on the first slide. | Alt+V | Option+V |
| Start Slideshow from BeginningOpens the slideshow at the first slide of the notebook, wherever the focus happens to be. | Alt+Shift+V | Option+Shift+V |
Notebook 5
| Action | Windows / Linux | Mac |
|---|---|---|
| Save NotebookStores the current state of the notebook straight away, without pinning the revision as the row below does. | Ctrl+S | Cmd+SorCtrl+S |
| Save and Pin RevisionStores the notebook and marks the saved version as pinned in the revision history, where it can be restored later. | Ctrl+MthenS | Cmd+MthenSorCtrl+MthenS |
| Open NotebookBrings up the dialog for choosing a notebook from recent files, Google Drive, GitHub or an upload. | Ctrl+O | Cmd+OorCtrl+O |
| Print NotebookSends the whole notebook to the browser's print dialog. | Ctrl+P | Cmd+PorCtrl+P |
| Add a CommentAttaches a comment thread to the focused cell for collaborators to read; it does not comment out code. | Ctrl+Alt+M | Cmd+Option+MorCtrl+Option+M |
No row on this page matches that filter.
Notes
→ Related guide: Keyboard shortcuts every data scientist should know
Running cells
Ctrl + Enter runs the focused cell, Shift + Enter runs it and selects the next cell, and Alt + Enter runs it and inserts a new cell. To run everything use Ctrl + F9: Ctrl + Shift + Enter is listed as Run selection, not Run all. Ctrl + F8 runs the cells before the current one and Ctrl + F10 runs the focused cell and all cells below it. Ctrl + M, I interrupts execution and Ctrl + M, . restarts the session.
The Ctrl + M prefix
Colab's shortcut list says Ctrl + M can be used as a prefix for multi-key-event shortcuts, so most cell commands take two steps: press Ctrl + M, release, then a letter. Ctrl + M, B and Ctrl + M, A insert a code cell below and above, Ctrl + M, D deletes the cell or selection, and Ctrl + M, Y and Ctrl + M, M convert a cell to code or text. Ctrl + M, K and Ctrl + M, J move the selected cells up and down. Commands that show Set shortcut in the dialog have no default key; click the box and type the keys you want.
Editing inside a cell
Ctrl + / comments the current line and Shift + Tab unindents it. Ctrl + Space / Tab opens autocomplete and Tab toggles docstring help, but Colab marks both Tab entries as applying only if automatic code completions are disabled under Settings. Find next and find previous are Ctrl + G and Ctrl + Shift + G, global find/replace is Ctrl + H, and Ctrl + Shift + H replaces all in the current cell. Ctrl + ] and Ctrl + [ collapse and expand sections.
Questions
How do I delete a cell in Google Colab?
Press Ctrl + M, D. It is a sequence, not a single chord: press Ctrl and M together, let go, then press D. Colab deletes the focused cell, or the whole selection when several cells are selected. On a Mac the prefix can be pressed with Cmd or Ctrl.
To bring a deleted cell back, press Ctrl and M together and then Z, which undoes the last cell action. The Edit menu has the same commands as Delete selected cells and Undo.
How do I run all cells in Google Colab?
Press Ctrl + F9, or open the Runtime menu and choose Run all. Colab then runs every cell in the notebook in order, from the first cell down. On a Mac, Cmd can be used in place of Ctrl.
Ctrl + Shift + Enter is a different command, Run selection, and does not run the whole notebook. To run only the current cell, press Ctrl + Enter. The Runtime menu also offers Run before, Run cell and below, and Restart session and run all.
Sources and checks
- Google Colab — Tools › Keyboard shortcuts (Windows / Linux display) Colab's own list of default shortcuts (Keyboard preferences dialog, editor key bindings "default"), as printed on Windows and Linux.
- Google Colab — Tools › Keyboard shortcuts (Mac display) The same list as Colab prints it on a Mac (⌘/Ctrl where either key works).
Every row on this page was matched to a line in the documentation above on . A binding that could not be found there is not listed.
3 rows from the earlier version of this page were removed in that check: duplicates, and bindings the documentation does not list or lists differently.
Found a wrong or missing key? Tell us and it gets checked against the source. How we verify describes the process and its limits.