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.
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
89You must run `python -m ipykernel install --user` to install the kernel.
90
91## Language specific instructions
92
93### Python {#python}
94
95#### Global environment
96
97<div class="warning">
98
99On 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.
100
101</div>
102
103
104To setup your current python to have an available kernel, run:
105
106```
107pip install ipykernel
108python -m ipykernel install --user
109```
110
111#### Conda Environment
112
113```
114source activate myenv
115conda install ipykernel
116python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
117```
118
119
120#### Virtualenv with pip
121
122```
123source activate myenv
124pip install ipykernel
125python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
126```
127
128### Typescript: Deno {#typescript-deno}
129
130[Install Deno](https://docs.deno.com/runtime/manual/getting_started/installation/) and then install the Deno jupyter kernel:
131
132```
133deno jupyter --unstable --install
134```
135
136### Other languages
137
138The following languages and kernels are also supported. You can help us out by expanding their installation instructions and configuration:
139
140* [Julia (IJulia)](https://github.com/JuliaLang/IJulia.jl)
141* R
142 - [Ark Kernel](https://github.com/posit-dev/ark) - via Positron, formerly RStudio
143 - [Xeus-R](https://github.com/jupyter-xeus/xeus-r)
144* [Scala (almond)](https://almond.sh/docs/quick-start-install)