1# REPL
2
3Read. Eval. Print. Loop.
4
5<div class="warning">
6
7This feature is in active development. Details may change. We're delighted to get feedback as the REPL feature evolves.
8
9</div>
10
11## Getting started
12
13Bring the power of [Jupyter kernels](https://docs.jupyter.org/en/latest/projects/kernels.html) to your editor! The built-in REPL for Zed allows you to run code interactively in your editor similarly to a notebook with your own text files.
14
15<!-- TODO: Include GIF in action -->
16
17To start using the REPL, add the following to your Zed `settings.json`:
18
19```json
20{
21 "jupyter": {
22 "enabled": true
23 }
24}
25```
26
27## Installation
28
29Zed supports running code in multiple languages. To get started, you need to install a kernel for the language you want to use.
30
31**Currently supported languages:**
32
33* [Python (ipykernel)](#python)
34* [TypeScript (Deno)](#typescript-deno)
35
36
37Once installed, you can start using the REPL in the respective language files, or other places those languages are supported, such as Markdown.
38
39<!-- TODO: Make markdown a link with an example -->
40
41## Using the REPL
42
43To start the REPL, open a file with the language you want to use and use the `repl: run` command (defaults to CMD + Enter on macOS). You can also click on the REPL icon in the toolbar.
44
45The `repl: run` command will be executed on your selection(s), and the result will be displayed below the selection.
46
47Outputs can be cleared with the `repl: clear outputs` command, or from the REPL menu in the toolbar.
48
49## Changing which kernel is used per language {#changing-kernels}
50
51Assign kernels by name to languages in your `settings.json`.
52
53```jsonc
54{
55 "jupyter": {
56 "kernels": {
57 "python": "conda-env",
58 "typescript": "deno-debug"
59 }
60 }
61}
62```
63
64If you have `jupyter` installed, you can run `juptyer kernelspec list` to see the available kernels. Note that only
65
66````
67$ jupyter kernelspec list
68Available kernels:
69 ark /Users/z/Library/Jupyter/kernels/ark
70 conda-base /Users/z/Library/Jupyter/kernels/conda-base
71 deno /Users/z/Library/Jupyter/kernels/deno
72 deno-debug /Users/z/Library/Jupyter/kernels/deno-debug
73 deno-release /Users/z/Library/Jupyter/kernels/deno-release
74 python-chatlab-dev /Users/z/Library/Jupyter/kernels/python-chatlab-dev
75 python3 /Users/z/Library/Jupyter/kernels/python3
76 ruby /Users/z/Library/Jupyter/kernels/ruby
77 rust /Users/z/Library/Jupyter/kernels/rust
78```
79
80Note: Zed will not find kernels nested within your Python `sys.prefix`, shown here as `/Users/z/.pyenv/versions/miniconda3-latest/`.
81
82```
83$ jupyter kernelspec list
84Available kernels:
85 conda-base /Users/z/Library/Jupyter/kernels/conda-base
86 python3 /Users/z/.pyenv/versions/miniconda3-latest/share/jupyter/kernels/python3
87```
88
89## Language specific instructions
90
91### Python {#python}
92
93#### Global environment
94
95<div class="warning">
96
97On MacOS, your system Python will _not_ work. Either set up [pyenv](https://github.com/pyenv/pyenv?tab=readme-ov-file#installation) or use a virtual environment.
98
99</div>
100
101
102To setup your current python to have an available kernel, run:
103
104```
105pip install ipykernel
106python -m ipykernel install --user
107```
108
109#### Conda Environment
110
111```
112source activate myenv
113conda install ipykernel
114python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
115```
116
117
118#### Virtualenv with pip
119
120```
121source activate myenv
122pip install ipykernel
123python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
124```
125
126### Typescript: Deno {#typescript-deno}
127
128[Install Deno](https://docs.deno.com/runtime/manual/getting_started/installation/) and then install the Deno jupyter kernel:
129
130```
131deno jupyter --unstable --install
132```
133
134### Other languages
135
136The following languages and kernels are also supported. You can help us out by expanding their installation instructions and configuration:
137
138* [Julia (IJulia)](https://github.com/JuliaLang/IJulia.jl)
139* R
140 - [Ark Kernel](https://github.com/posit-dev/ark) - via Positron, formerly RStudio
141 - [Xeus-R](https://github.com/jupyter-xeus/xeus-r)
142* [Scala (almond)](https://almond.sh/docs/quick-start-install)