Jupyter Notebook Modes

Jupyter Notebook Modes

There are two modes in Jupyter. These are edit mode and command mode. If the cell has a green border, that means you’re in edit mode. If the cell has a blue border, then you’re in command mode. Edit mode is for all the actions you would usually perform in the context of the cell. When you are editing and typing your code and text, this is edit mode. Command mode is for doing things outside the scope of any individual cell, often applying actions to multiple cells at once. For example, you can select multiple cells, copy them, and paste them, or delete them if you like. The shortcut menu provides a list that helps with understanding the difference between these two modes.

Edit Mode

jupyter cell edit mode

Command Mode

jupyter cell command mode

List All Jupyter Keyboard Shortcuts

Using the help menu, you can find the keyboard shortcuts. Clicking here will give you all of the keyboard shortcuts for both command mode and edit mode.
list all jupyter keyboard shortcuts

Reviewing this list will help cement the difference between these two modes.

Command Mode

F: find and replace
Ctrl-Shift-F: open the command palette
Ctrl-Shift-P: open the command palette
Enter: enter edit mode
P: open the command palette
Shift-Enter: run cell, select below
Ctrl-Enter: run selected cells
Alt-Enter: run cell and insert below
Y: change cell to code
M: change cell to markdown
R: change cell to raw
1: change cell to heading 1
2: change cell to heading 2
3: change cell to heading 3
4: change cell to heading 4
5: change cell to heading 5
6: change cell to heading 6
K: select cell above
Up: select cell above
Down: select cell below
J: select cell below
Shift-K: extend selected cells above
Shift-Up: extend selected cells above
Shift-Down: extend selected cells below

Shift-J: extend selected cells below
Ctrl-A: select all cells
A: insert cell above
B: insert cell below
X: cut selected cells
C: copy selected cells
Shift-V: paste cells above
V: paste cells below
Z: undo cell deletion
D,D: delete selected cells
Shift-M: merge selected cells, or current cell with cell below if only one cell is selected
Ctrl-S: Save and Checkpoint
S: Save and Checkpoint
L: toggle line numbers
O: toggle output of selected cells
Shift-O: toggle output scrolling of selected cells
H: show keyboard shortcuts
I,I: interrupt the kernel
0,0: restart the kernel (with dialog)
Esc: close the pager
Q: close the pager
Shift-L: toggles line numbers in all cells, and persist the setting
Shift-Space: scroll notebook up
Space: scroll notebook down

Edit Mode

Tab: code completion or indent
Shift-Tab: tooltip
Ctrl-]: indent
Ctrl-[: dedent
Ctrl-A: select all
Ctrl-Z: undo
Ctrl-/: comment
Ctrl-D: delete whole line
Ctrl-U: undo selection
Insert: toggle overwrite flag
Ctrl-Home: go to cell start
Ctrl-Up: go to cell start
Ctrl-End: go to cell end
Ctrl-Down: go to cell end
Ctrl-Left: go one word left

Ctrl-Right: go one word right
Ctrl-Backspace: delete word before
Ctrl-Delete: delete word after
Ctrl-Y: redo
Alt-U: redo selection
Ctrl-M: enter command mode
Ctrl-Shift-F: open the command palette
Ctrl-Shift-P: open the command palette
Esc: enter command mode
Shift-Enter: run cell, select below
Ctrl-Enter: run selected cells
Alt-Enter: run cell and insert below
Ctrl-Shift-Minus: split cell at cursor
Ctrl-S: Save and Checkpoint
Down: move cursor down
Up: move cursor up


Commonly Used Jupyter Shortcuts

To easily comment or uncomment a line of code in Jupyter, you can use the Ctrl-/ shortcut.

jupyter comment shortcut

The Shift-Enter runs the current cell and moves the cursor to a new cell below.

Jupyter Shift Enter shortcut

The Ctrl-Shift-Minus can be used to split a cell in two.

jupyter control shift minus

The esc key will put you back into command mode.

jupyter escape to command mode

The Shift-Up hotkey allows us to select multiple cells startring from lower to upper.

juypter shift up cells

With multiple cells selected, we can merge them back together with Shift-M.

jupyter merge cells

While in command mode, we can use Ctrl-C and Ctrl-V to copy the entire contents to a new cell.

jupyter command mode copy paste

This is good for when you want to change the inputs to a graph for example. We can leave the code in the first cell, but change the string in the second cell and run the cells to see what kind of difference that makes on the output. Quite handy! To run both or all cells at once, we can use the Cell menu, then select Run All.

jupyter run all cells

Now we can see how the code produces different outputs since we were able to simply change a string in the second cell.

jupyter run all cells comparison

If you need to quickly view all the available shortcuts, just press the h key on your keyboard.

jupyter display all shortcuts

To view the full command palette, just press the p key. Once that is done, you can type in the provided text input field and your results instantly show up in the dropdown list. Very nice.

jupyter view command palette

Jupyter Notebook Modes Summary

In this tutorial, we had a look at the modes available for use in the Jupyter notebook. These are the command mode and edit mode. Each mode is for specific tasks. There are many shortcuts available to use, some in command mode, some in edit mode, and some that exist in both modes. Practicing these modes and shortcuts will help you to become more familiar with working in Jupyter Notebooks.