Table of Contents

Working with Julia notebooks

A Julia notebook has three types of cells

  1. Textual annotation, written in the Markdown mark-up language (see also wikipedia).
  2. Live Julia code
  3. Graphical output

Our first concern is working with the live Julia code cells. I'll illustrate on the “Numbers, variables, and basic functions” notebook from the Hands-on Julia tutorial. You should start that notebook and follow along (see julia-notebooks).


Executing a line of code with shift-enter

1. Click on the line In [ ]: typeof(10). The line will be highlighted with a green box, and you should see a blinking cursor after typeof(10).

2. Hold down the shift key while pressing “enter” (we'll call this “shift-enter”). This will make the Julia computational engine execute the line of Julia code and print its return value. You should now see the following. Note that Julia has told us that the value 10 has type Int64, i.e. 64-bit integer.

3. Try clicking on the typeof(10) line again, modifying it to read typeof(10.0), and hitting shift-enter. You will see that the type of 10.0 is Float64, i.e. a 64-bit floating-point number.


Adding a new Julia-code cell with ctrl-m-b

The notebook has asked you to try a few calculations even before the typeof(10) statement. To do this, click on the section of text starting [1] Type different types of integers … and then either select Insert → Insert Cell Below from the menu, or use the quicker keyboard shortcut “control-m b” (or “ctrl-m b”). That is, hold the control key, type “m”, and then let go of control and type “b”. This will insert an empty Julia-code cell, which you can type Julia commands into and execute with shift-enter. After entering the suggested 3/4 and hitting shift-enter, you'll see


Execute and add new cell with alt-enter

When you want to execute a bunch of commands, it can get tedious to keep opening new cells. The “alt-enter” shortcut executes the current cell then immediately starts a new cell below. I've used “alt-enter” to compute a few powers of 10 as the notebook suggests.


Summary of notebook keyboard shortcuts

All actions in the notebook can be performed with the mouse, but keyboard shortcuts are also available for the most common ones. The essential shortcuts to remember are the following:

Shift-Enter: run cell. Execute the current cell, show output (if any), and jump to the next cell below. If Shift-Enter is invoked on the last cell, a new code cell will also be created. Note that in the notebook, typing Enter on its own never forces execution, but rather just inserts a new line in the current cell. Shift-Enter is equivalent to clicking the Cell | Run menu item.

Ctrl-Enter: run cell in-place. Execute the current cell as if it were in “terminal mode”, where any output is shown, but the cursor remains in the current cell. The cell’s entire contents are selected after execution, so you can just start typing and only the new input will be in the cell. This is convenient for doing quick experiments in place, or for querying things like filesystem content, without needing to create additional cells that you may not want to be saved in the notebook.

Alt-Enter: run cell, insert below. Executes the current cell, shows the output, and inserts a new cell between the current cell and the cell below (if one exists). This is thus a shortcut for the sequence Shift-Enter, Ctrl-m a. (Ctrl-m a adds a new cell above the current one.)

Ctrl-m: This is the prefix for all other shortcuts, which consist of Ctrl-m followed by a single letter or character. For example, if you type Ctrl-m h (that is, the sole letter h after Ctrl-m), IPython will show you all the available keyboard shortcuts.

Here is the complete set of keyboard shortcuts available:

Shortcut Action
Shift-Enter run cell
Ctrl-Enter run cell in-place
Alt-Enter run cell, insert below
Ctrl-m x cut cell
Ctrl-m c copy cell
Ctrl-m v paste cell
Ctrl-m d delete cell
Ctrl-m z undo last cell deletion
Ctrl-m - split cell
Ctrl-m a insert cell above
Ctrl-m b insert cell below
Ctrl-m o toggle output
Ctrl-m O toggle output scroll
Ctrl-m l toggle line numbers
Ctrl-m s save notebook
Ctrl-m j move cell down
Ctrl-m k move cell up
Ctrl-m y code cell
Ctrl-m m markdown cell
Ctrl-m t raw cell
Ctrl-m 1-6 heading 1-6 cell
Ctrl-m p select previous
Ctrl-m select next
Ctrl-m interrupt kernel
Ctrl-m . restart kernel
Ctrl-m h show keyboard shortcuts

For more about controlling your Julia notebook, see the iPython notebook documentation, from where this summary of shortcuts was copied.