# Editors

> Choose what testlane code opens a workspace in, from a preset like zed or nvim to a command of your own.

`testlane <project> <ref> code` opens a workspace in your editor, so you can go from a branch name to reading its code in one command. You pick the editor once, with a preset name or a command of your own, and Testlane works out how to launch it and whether to wait for it.

## At a glance

| Aspect          | Editors                                                                         |
| --------------- | ------------------------------------------------------------------------------- |
| Where to set it | `editor` in the project file, then `editor` in `defaults.toml`                  |
| Default         | `code`, which opens Visual Studio Code                                          |
| For one run     | `--editor <preset or template>` on `code`                                       |
| Presets         | `zed`, `code`, `cursor`, `windsurf`, `idea`, `webstorm`, `phpstorm`, `goland`, `vim`, `nvim`, `helix`, `hx` and `terminal` |
| Your own        | Any other string, run with `bash -c`, with `{path}` for the workspace           |
| Waiting         | Terminal editors keep `code` in the foreground, and the rest return at once      |
| Check it        | `code --dry-run` prints what it would launch, and `testlane doctor` checks a preset is installed |

## Pick an editor

Set `editor` in a project file, or in `defaults.toml` for every project that doesn't set its own:

```toml [~/.testlane/my-project.toml]
editor = "zed"
```

Without either, Testlane opens `code`. To use another editor for one run, pass `--editor`:

```bash
testlane my-project 42 code --editor vim
```

## Presets

A preset is an editor Testlane already knows how to launch, so you only need its name:

| Preset                                   | What Testlane runs                                   | Does `code` wait? |
| ---------------------------------------- | ---------------------------------------------------- | ----------------- |
| `zed`                                    | `zed <path>`                                         | No                |
| `code`                                   | `code --new-window <path>`                           | No                |
| `cursor`                                 | `cursor --new-window <path>`                         | No                |
| `windsurf`                               | `windsurf <path>`                                    | No                |
| `idea`, `webstorm`, `phpstorm`, `goland` | `<name> <path>`                                      | No                |
| `vim`, `nvim`, `helix`, `hx`             | `<name> <path>`                                      | Yes               |
| `terminal`                               | Your `$SHELL`, or `bash`, in the workspace           | Yes               |

Graphical editors start in the background, so `code` returns straight away. Terminal editors and `terminal` keep the foreground until you quit them.

`testlane doctor` checks that a preset's program is on your `PATH`, and warns when it isn't, so you find out before the first `code` fails.

## Templates of your own

Any `editor` that isn't a preset name is a template: a command Testlane runs with `bash -c`. Put `{path}` where the workspace's path goes, and Testlane quotes it for the shell:

```toml [~/.testlane/my-project.toml]
editor = "emacsclient -n {path}"
```

All the [template variables](https://testlane.dev/docs/configuration/environment-and-templates) work here, not only `{path}`. Testlane doesn't check that a template has `{path}`, so one without it opens your editor without the workspace.

## Wait for the editor

A template starts in the background, so `code` returns straight away. End it with `:wait` to keep `code` in the foreground until the editor exits, which you'll want when `code` is one step of a script:

```toml [~/.testlane/my-project.toml]
editor = "kak {path}:wait"
```

`:wait` works only at the end of a template. Presets wait or not as the table above shows.

## Check what would launch

`--dry-run` prints the command `code` would run, after the steps that create the workspace, and opens nothing:

```bash
testlane my-project feat/login code --dry-run --editor 'emacsclient -n {path}'
```

```
mkdir -p /home/you/dev/testlane/my-project/trees
git -C /home/you/dev/testlane/my-project/repo fetch --no-tags origin --end-of-options feat/login
git -C /home/you/dev/testlane/my-project/repo worktree add /home/you/dev/testlane/my-project/trees/feat-login -B feat/login --track origin/feat/login
mkdir -p /home/you/dev/testlane/my-project/trees/.data/feat-login
bash -c 'emacsclient -n /home/you/dev/testlane/my-project/trees/feat-login'
```

`code` doesn't take `--json`, since it opens a program rather than printing a result. Asking for both stops with `E_USAGE` and exit `2`.
