Skip to content

Useful shortcuts in jupyter notebook & colab

jupyter notebook shortcuts

Jupyter Notebook has many helpful keyboard shortcuts that can speed up your workflow. Here are the most commonly used ones:

General Shortcuts

  • Shift + Enter: Run the current cell and move to the next cell.
  • Ctrl + Enter: Run the current cell and stay in the cell.
  • Alt + Enter: Run the current cell and insert a new cell below.

Command Mode (press Esc to enter)

  • A: Insert a cell above.
  • B: Insert a cell below.
  • X: Cut the current cell.
  • C: Copy the current cell.
  • V: Paste the cell below.
  • D, D (press D twice): Delete the selected cell.
  • Z: Undo cell deletion.
  • Y: Change the cell to code.
  • M: Change the cell to markdown.
  • 16: Change the cell to a markdown header (e.g., 1 for H1, 2 for H2).
  • Shift + Up/Down: Select multiple cells.
  • Ctrl + Shift + -: Split the cell at the cursor.

Edit Mode (press Enter to enter)

  • Ctrl + Shift + -: Split cell at the cursor.
  • Tab: Indent code or trigger code completion.
  • Shift + Tab: Show tooltip (documentation) for a function.
  • Ctrl + /: Toggle comment on selected line(s).

Navigation Shortcuts

  • Up/Down Arrow: Move up or down through cells.
  • Enter: Switch from command mode to edit mode for the selected cell.
  • Esc: Switch from edit mode to command mode.

Run & Kernel Management

  • 0, 0 (press 0 twice): Restart the kernel.
  • Shift + M: Merge selected cells.

Help and Documentation

  • Shift + Tab (press up to 4 times): Display documentation for the object in focus.
  • Ctrl + Shift + P: Open the command palette.

Magic Commands (typed in a cell)

  • %time: Time execution of a single statement.
  • %%timeit: Time execution of a cell multiple times.
  • %run: Run a Python script.
  • %matplotlib inline: Display plots inline (useful for data visualization).
See also  google-generativeai & google-genai: a detailed comparison with integration guides

These shortcuts make working in Jupyter Notebook more efficient by reducing the need to switch between keyboard and mouse. You can also customize and view additional shortcuts via the Help > Keyboard Shortcuts menu.


Shortcuts in colab

Google Colab shares many similar shortcuts with Jupyter Notebook but has its own set tailored for a browser-based interface. Here’s a list of the essential shortcuts for Colab:

General Shortcuts

  • Shift + Enter: Run the current cell and move to the next cell.
  • Ctrl + Enter: Run the current cell and stay in the cell.
  • Alt + Enter: Run the current cell and insert a new cell below.

Command Mode (press Esc to enter)

  • A: Insert a cell above.
  • B: Insert a cell below.
  • C: Copy the selected cell.
  • X: Cut the selected cell.
  • V: Paste cell below.
  • D, D (press D twice): Delete the selected cell.
  • Z: Undo cell deletion.
  • M: Change the cell to Markdown.
  • Y: Change the cell to code.
  • Ctrl + Shift + -: Split the cell at the cursor.

Edit Mode (press Enter to enter)

  • Tab: Indent code or trigger code completion.
  • Shift + Tab: Show tooltip (documentation) for a function.
  • Ctrl + /: Toggle comment on selected line(s).
  • Ctrl + M, M: Convert cell to Markdown.
  • Ctrl + M, Y: Convert cell to code.

Run & Kernel Management

  • Ctrl + M, .: Interrupt execution.
  • Ctrl + M, H: Show all shortcuts.
  • Ctrl + M, L: Toggle line numbers in code cells.
  • Ctrl + M, S: Save notebook.

Navigation

  • Ctrl + M, A: Add cell above.
  • Ctrl + M, B: Add cell below.
  • Ctrl + M, D: Delete the cell.
  • Ctrl + M, Z: Undo cell deletion.
  • Ctrl + M, Enter: Run selected cell and keep focus.
  • Ctrl + M, J: Move to the cell below.
  • Ctrl + M, K: Move to the cell above.
See also  Data Parallelism & Model Parallelism

Special Magic Commands (typed in a cell)

  • %time: Measure execution time of a single line.
  • %%timeit: Measure execution time of the entire cell multiple times.
  • %matplotlib inline: Display matplotlib plots inline.

These shortcuts are essential for efficient work in Google Colab, reducing the need for switching between keyboard and mouse. You can access more shortcuts by pressing Ctrl + M, H to view the full list in Colab.

Leave a Reply

error: Content is protected !!