yaml.md

  1---
  2title: YAML
  3description: "Configure YAML language support in Zed, including language servers, formatting, and debugging."
  4---
  5
  6# YAML
  7
  8YAML support is available natively in Zed.
  9
 10- Tree-sitter: [zed-industries/tree-sitter-yaml](https://github.com/zed-industries/tree-sitter-yaml)
 11- Language Server: [redhat-developer/yaml-language-server](https://github.com/redhat-developer/yaml-language-server)
 12
 13## Configuration
 14
 15You can configure various [yaml-language-server settings](https://github.com/redhat-developer/yaml-language-server?tab=readme-ov-file#language-server-settings) by adding them to your Zed settings.json in a `yaml-language-server` block under the `lsp` key.
 16
 17You can configure custom YAML schemas using relative paths. Zed resolves paths relative to your project root:
 18
 19```json [settings]
 20  "lsp": {
 21    "yaml-language-server": {
 22      "settings": {
 23        "yaml": {
 24          "keyOrdering": true,
 25          "format": {
 26            "singleQuote": true
 27          },
 28          "schemas": {
 29              "https://getcomposer.org/schema.json": ["/*"],
 30              "./schemas/kubernetes.yaml": "k8s/**/*.yaml",
 31              "~/global-schemas/docker-compose.yaml": "docker-compose*.yml"
 32          }
 33        }
 34      }
 35    }
 36  }
 37```
 38
 39Paths starting with `./` resolve relative to the worktree root. Paths starting with `~/` expand to your home directory.
 40
 41Note, settings keys must be nested, so `yaml.keyOrdering` becomes `{"yaml": { "keyOrdering": true }}`.
 42
 43## Formatting
 44
 45By default, Zed uses Prettier for formatting YAML files.
 46
 47### Prettier Formatting
 48
 49You can customize the formatting behavior of Prettier. For example to use single-quotes in yaml files add the following to your `.prettierrc` configuration file:
 50
 51```json
 52{
 53  "overrides": [
 54    {
 55      "files": ["*.yaml", "*.yml"],
 56      "options": {
 57        "singleQuote": false
 58      }
 59    }
 60  ]
 61}
 62```
 63
 64### yaml-language-server Formatting
 65
 66To use `yaml-language-server` instead of Prettier for YAML formatting, configure in Settings ({#kb zed::OpenSettings}) under Languages > YAML, or add to your settings file:
 67
 68```json [settings]
 69  "languages": {
 70    "YAML": {
 71      "formatter": "language_server"
 72    }
 73  }
 74```
 75
 76## Schemas
 77
 78By default yaml-language-server will attempt to determine the correct schema for a given yaml file and retrieve the appropriate JSON Schema from [Json Schema Store](https://schemastore.org/).
 79
 80You can override any auto-detected schema via the `schemas` settings key (demonstrated above) or by providing an [inlined schema](https://github.com/redhat-developer/yaml-language-server#using-inlined-schema) reference via a modeline comment at the top of your yaml file:
 81
 82```yaml
 83# yaml-language-server: $schema=https://www.schemastore.org/github-action.json
 84name: Issue Assignment
 85on:
 86  issues:
 87    types: [opened]
 88```
 89
 90You can disable the automatic detection and retrieval of schemas from the JSON Schema if desired:
 91
 92```json [settings]
 93  "lsp": {
 94    "yaml-language-server": {
 95      "settings": {
 96        "yaml": {
 97          "schemaStore": {
 98            "enable": false
 99          }
100        }
101      }
102    }
103  }
104```
105
106## Custom Tags
107
108Yaml-language-server supports [custom tags](https://github.com/redhat-developer/yaml-language-server#adding-custom-tags) which can be used to inject custom application functionality at runtime into your yaml files.
109
110For example Amazon CloudFormation YAML uses a number of custom tags, to support these you can add the following to your settings.json:
111
112```json [settings]
113  "lsp": {
114    "yaml-language-server": {
115      "settings": {
116        "yaml": {
117          "customTags": [
118            "!And scalar",
119            "!And mapping",
120            "!And sequence",
121            "!If scalar",
122            "!If mapping",
123            "!If sequence",
124            "!Not scalar",
125            "!Not mapping",
126            "!Not sequence",
127            "!Equals scalar",
128            "!Equals mapping",
129            "!Equals sequence",
130            "!Or scalar",
131            "!Or mapping",
132            "!Or sequence",
133            "!FindInMap scalar",
134            "!FindInMap mapping",
135            "!FindInMap sequence",
136            "!Base64 scalar",
137            "!Base64 mapping",
138            "!Base64 sequence",
139            "!Cidr scalar",
140            "!Cidr mapping",
141            "!Cidr sequence",
142            "!Ref scalar",
143            "!Ref mapping",
144            "!Ref sequence",
145            "!Sub scalar",
146            "!Sub mapping",
147            "!Sub sequence",
148            "!GetAtt scalar",
149            "!GetAtt mapping",
150            "!GetAtt sequence",
151            "!GetAZs scalar",
152            "!GetAZs mapping",
153            "!GetAZs sequence",
154            "!ImportValue scalar",
155            "!ImportValue mapping",
156            "!ImportValue sequence",
157            "!Select scalar",
158            "!Select mapping",
159            "!Select sequence",
160            "!Split scalar",
161            "!Split mapping",
162            "!Split sequence",
163            "!Join scalar",
164            "!Join mapping",
165            "!Join sequence",
166            "!Condition scalar",
167            "!Condition mapping",
168            "!Condition sequence"
169          ]
170        }
171      }
172    }
173  }
174```