repl.md

  1# REPL
  2
  3## Getting started
  4
  5Bring 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.
  6
  7<!-- TODO: Include GIF in action -->
  8
  9## Installation
 10
 11Zed supports running code in multiple languages. To get started, you need to install a kernel for the language you want to use.
 12
 13**Currently supported languages:**
 14
 15* [Python (ipykernel)](#python)
 16* [TypeScript (Deno)](#typescript-deno)
 17
 18Once installed, you can start using the REPL in the respective language files, or other places those languages are supported, such as Markdown.
 19
 20<!-- TODO: Make markdown a link with an example -->
 21
 22## Using the REPL
 23
 24To 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.
 25
 26The `repl: run` command will be executed on your selection(s), and the result will be displayed below the selection.
 27
 28Outputs can be cleared with the `repl: clear outputs` command, or from the REPL menu in the toolbar.
 29
 30## Language specific instructions
 31
 32### Python {#python}
 33
 34#### Global environment
 35
 36<div class="warning">
 37
 38On 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.
 39
 40</div>
 41
 42To setup your current python to have an available kernel, run:
 43
 44```
 45pip install ipykernel
 46python -m ipykernel install --user
 47```
 48
 49#### Conda Environment
 50
 51```
 52source activate myenv
 53conda install ipykernel
 54python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
 55```
 56
 57#### Virtualenv with pip
 58
 59```
 60source activate myenv
 61pip install ipykernel
 62python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
 63```
 64
 65### Typescript: Deno {#typescript-deno}
 66
 67[Install Deno](https://docs.deno.com/runtime/manual/getting_started/installation/) and then install the Deno jupyter kernel:
 68
 69```
 70deno jupyter --install
 71```
 72
 73### Other languages
 74
 75The following languages and kernels are also supported. You can help us out by expanding their installation instructions and configuration:
 76
 77* [Julia (IJulia)](https://github.com/JuliaLang/IJulia.jl)
 78* R
 79  - [Ark Kernel](https://github.com/posit-dev/ark) - via Positron, formerly RStudio
 80  - [Xeus-R](https://github.com/jupyter-xeus/xeus-r)
 81* [Scala (almond)](https://almond.sh/docs/quick-start-install)
 82
 83## Changing which kernel is used per language {#changing-kernels}
 84
 85Zed automatically detects the available kernels on your system. If you need to configure a different default kernel for a
 86language, you can assign a kernel for any supported language in your `settings.json`.
 87
 88```jsonc
 89{
 90  "jupyter": {
 91    "kernel_selections": {
 92      "python": "conda-env",
 93      "typescript": "deno",
 94      "javascript": "deno"
 95    }
 96  }
 97}
 98```
 99
100If you have `jupyter` installed, you can run `jupyter kernelspec list` to see the available kernels.
101
102```
103$ jupyter kernelspec list
104Available kernels:
105  ark                   /Users/z/Library/Jupyter/kernels/ark
106  conda-base            /Users/z/Library/Jupyter/kernels/conda-base
107  deno                  /Users/z/Library/Jupyter/kernels/deno
108  python-chatlab-dev    /Users/z/Library/Jupyter/kernels/python-chatlab-dev
109  python3               /Users/z/Library/Jupyter/kernels/python3
110  ruby                  /Users/z/Library/Jupyter/kernels/ruby
111  rust                  /Users/z/Library/Jupyter/kernels/rust
112```
113
114Note: Zed will not find kernels nested within your Python `sys.prefix`, shown here as `/Users/z/.pyenv/versions/miniconda3-latest/`.
115
116```
117$ jupyter kernelspec list
118Available kernels:
119  conda-base            /Users/z/Library/Jupyter/kernels/conda-base
120  python3               /Users/z/.pyenv/versions/miniconda3-latest/share/jupyter/kernels/python3
121```
122
123You must run `python -m ipykernel install --user` to install the kernel.