What is Jupyter Notebook?
Jupyter Notebook is widely used for data analysis. I started to learn Data Science 2–3 months ago and I used this tool to explore some datasets (a collection of data). It’s awesome!
The notebooks documents are documents produced by the Jupyter Notebook App, which can contain both code (e.g. Python) and rich text elements (paragraphs, equations, links, etc..).
Let’s see the definition from the docs.
The Jupyter Notebook App is a client-server application that allows editing and running notebook documents by a browser.
Shortcuts
As a developer, I like to use shortcuts and snippets as much as I can. They just make writing code a lot easier and faster. I like to follow one rule:
If you start doing some action with the mouse, stop and think if there is a shortcut. If there is a one - use it.
When I started using Jupyter Notebook I didn’t know that there are shortcuts for this tool. Several times, I changed my cell type from code to markdown and I didn’t know how. As you can guess this caused me a lot of headache. One day I just saw that there is a Help > Keyboard Shortcuts
link in the menu bar. To my surprise, it turned out that Jupyter Notebook has a ton of shortcuts.
In this article, I’ll show you my favorite ones. Note that the shortcuts are for Windows
and Linux
users. Anyway, for the Mac
users, they’re different buttons for Ctrl
, Shift
, and Alt
:
Ctrl
: command key⌘
Shift
: Shift⇧
Alt
: option⌥
First, we need to know that they are 2 modes in the Jupyter Notebook App: command mode and edit mode. I’ll start with the shortcuts shared between the two modes.
Shortcuts in both modes:
Shift + Enter
run the current cell, select belowCtrl + Enter
run selected cellsAlt + Enter
run the current cell, insert belowCtrl + S
save and checkpoint
While in command mode (press Esc
to activate):
Enter
take you into edit modeH
show all shortcutsUp
select cell aboveDown
select cell belowShift + Up
extend selected cells aboveShift + Down
extend selected cells belowA
insert cell aboveB
insert cell belowX
cut selected cellsC
copy selected cellsV
paste cells belowShift + V
paste cells aboveD, D (press the key twice)
delete selected cellsZ
undo cell deletionS
Save and CheckpointY
change the cell type to CodeM
change the cell type to MarkdownP
open the command palette.
This dialog helps you run any command by name. It’s really useful if you don’t know some shortcut or when you don’t have a shortcut for the wanted command.Shift + Space
scroll notebook upSpace
scroll notebook downEsc
take you into command modeTab
code completion or indentShift + Tab
tooltipCtrl + ]
indentCtrl + [
dedentCtrl + A
select allCtrl + Z
undoCtrl + Shift + Z
orCtrl + Y
redoCtrl + Home
go to cell startCtrl + End
go to cell endCtrl + Left
go one word leftCtrl + Right
go one word rightCtrl + Shift + P
open the command paletteDown
move cursor downUp
move cursor up
While in edit mode (pressEnter
to activate)
These are the shortcuts I use in my daily work. If you still need something that is not mentioned here you can find it in the keyboard shortcuts dialog (H
). You can also edit existing or add more shortcuts from the Help > Edit Keyboard Shortcuts
link in the menu bar. Clicking the link will open a dialog. At the bottom of it there are rules for adding or editing shortcuts. You need to use hyphens -
to represent keys that should be pressed at the same time.
For example, I added a shortcut Ctrl-R
for the restart kernel and run all cells command.