tinkerlab.dev
/julia/20-repl-and-unicode

The REPL and Unicode

Modes

Key at an empty promptModePrompt
Juliajulia>
]Pkg(env) pkg>
?Helphelp?>
;Shellshell>
Backspaceback to Julia
julia> ?sort            # docs, all methods, related functions
julia> ]st              # one-off Pkg command without staying in the mode
julia> ;ls -la          # one-off shell command

Help mode also works on operators, macros, types and unicode characters — ?∘, ?@view, ?Vector, and pasting a character tells you its name and how to type it.

Keybindings

KeyDoes
Ctrl-Cinterrupt the running expression
Ctrl-Dexit (at an empty prompt)
Ctrl-Lclear screen
Ctrl-R / Ctrl-Sreverse / forward history search
Up/Downhistory, prefix-filtered by what you’ve typed
Alt-Enterinsert a newline without evaluating
Ctrl-Qedit the current line in $EDITOR
Tabcompletion — of names, paths, fields, and LaTeX sequences
Tab twiceshow all completions, including method signatures

Typing f( then Tab shows the applicable methods. Typing x. then Tab shows fields and properties.

Useful REPL functions

ans                       # value of the last expression
varinfo()                 # what's defined in Main, with sizes
varinfo(MyPkg)
clipboard("text"); clipboard()      # copy out / paste in
edit("file.jl", 10)       # open in $JULIA_EDITOR at a line
@edit f(1)                # open the source of the method that call selects
@which f(1)
@doc f
names(Base; all = false)
methods(f); methodswith(MyType)
apropos("sort")           # full-text search of docstrings
InteractiveUtils.versioninfo()

startup.jl

~/.julia/config/startup.jl runs before every session. Keep it small and fast.

try
    using Revise
catch e
    @warn "Revise failed to load" exception = (e, catch_backtrace())
end

atreplinit() do repl
    try
        @eval using OhMyREPL
    catch
    end
end

ENV["JULIA_EDITOR"] = "zed --wait"

Install these into the shared default environment, not into your projects:

julia -e 'using Pkg;
    Pkg.activate("v$(VERSION.major).$(VERSION.minor)"; shared=true);
    Pkg.add(["Revise", "OhMyREPL", "BenchmarkTools"])'

--startup-file=no skips it — useful for benchmarking and required for reproducible CI.

Command-line flags worth remembering

julia --project                  # activate the nearest Project.toml
julia -t auto                    # all available threads
julia -p 4                       # 4 worker processes (Distributed)
julia -e 'code'                  # evaluate and exit
julia -E 'code'                  # evaluate, print the result, exit
julia -i script.jl               # run then stay interactive
julia --check-bounds=yes         # bounds-check even where @inbounds says not to
julia --startup-file=no
julia --banner=no -q             # quiet
julia --track-allocation=user    # write .mem files with per-line allocation counts
julia --code-coverage=user

Unicode input

Type the LaTeX name and press Tab. Works in the REPL, and in editors with the Julia extension.

SequenceCharSequenceChar
\alphaα\le
\betaβ\ge
\gammaγ\ne
\deltaδ\approx
\DeltaΔ\equiv
\epsilonϵ\in
\thetaθ\notin
\lambdaλ\subseteq
\muμ\cup
\piπ\cap
\rhoρ\cdot
\sigmaσ\times×
\SigmaΣ\div÷
\phiϕ\circ
\omegaω\pm±
\OmegaΩ\sqrt
\infty\sum
\partial\prod
\nabla\int
\hbar\emptyset
\euler\im— (im is the literal)

Sub- and superscripts: x\_1 gives x₁, x\^2 gives , \_a through \_z and \^0 through \^9 mostly exist. These are legal in identifiers, so σ², x₁, Δt are all valid variable names.

Built-in constants: π (also pi), (also exp(1)), im (imaginary unit), Inf, NaN, missing, nothing.

Operators you can define yourself, because they’re parsed as infix: ⊕ ⊗ ⊙ ⊘ ⋆ ∘ ± ∓ × ⋅ ∪ ∩ ⊆ ⊇ ≈ ≉ ≡ and many more. Precedence follows the ASCII operator each resembles.

(a, b) = a + 2b
3 4       # 11

If you don’t want Unicode in your source, every operator has an ASCII spelling: in, issubset, isapprox, !=, <=, div, dot, cross, union, intersect, pi, sqrt.

Finding out what a character is

Paste it into help mode:

help?> ⊗
"⊗" can be typed by \otimes<tab>

That works for any character, which is the fastest way to read unfamiliar numerical code.