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. For example:
 16
 17```json [settings]
 18  "lsp": {
 19    "yaml-language-server": {
 20      "settings": {
 21        "yaml": {
 22          "keyOrdering": true,
 23          "format": {
 24            "singleQuote": true
 25          },
 26          "schemas": {
 27              "https://getcomposer.org/schema.json": ["/*"],
 28              "../relative/path/schema.json": ["/config*.yaml"]
 29          }
 30        }
 31      }
 32    }
 33  }
 34```
 35
 36Note, settings keys must be nested, so `yaml.keyOrdering` becomes `{"yaml": { "keyOrdering": true }}`.
 37
 38## Formatting
 39
 40By default, Zed uses Prettier for formatting YAML files.
 41
 42### Prettier Formatting
 43
 44You can customize the formatting behavior of Prettier. For example to use single-quotes in yaml files add the following to your `.prettierrc` configuration file:
 45
 46```json [settings]
 47{
 48  "overrides": [
 49    {
 50      "files": ["*.yaml", "*.yml"],
 51      "options": {
 52        "singleQuote": false
 53      }
 54    }
 55  ]
 56}
 57```
 58
 59### yaml-language-server Formatting
 60
 61To 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:
 62
 63```json [settings]
 64  "languages": {
 65    "YAML": {
 66      "formatter": "language_server"
 67    }
 68  }
 69```
 70
 71## Schemas
 72
 73By 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/).
 74
 75You 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:
 76
 77```yaml
 78# yaml-language-server: $schema=https://www.schemastore.org/github-action.json
 79name: Issue Assignment
 80on:
 81  issues:
 82    types: [opened]
 83```
 84
 85You can disable the automatic detection and retrieval of schemas from the JSON Schema if desired:
 86
 87```json [settings]
 88  "lsp": {
 89    "yaml-language-server": {
 90      "settings": {
 91        "yaml": {
 92          "schemaStore": {
 93            "enable": false
 94          }
 95        }
 96      }
 97    }
 98  }
 99```
100
101## Custom Tags
102
103Yaml-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.
104
105For example Amazon CloudFormation YAML uses a number of custom tags, to support these you can add the following to your settings.json:
106
107```json [settings]
108  "lsp": {
109    "yaml-language-server": {
110      "settings": {
111        "yaml": {
112          "customTags": [
113            "!And scalar",
114            "!And mapping",
115            "!And sequence",
116            "!If scalar",
117            "!If mapping",
118            "!If sequence",
119            "!Not scalar",
120            "!Not mapping",
121            "!Not sequence",
122            "!Equals scalar",
123            "!Equals mapping",
124            "!Equals sequence",
125            "!Or scalar",
126            "!Or mapping",
127            "!Or sequence",
128            "!FindInMap scalar",
129            "!FindInMap mapping",
130            "!FindInMap sequence",
131            "!Base64 scalar",
132            "!Base64 mapping",
133            "!Base64 sequence",
134            "!Cidr scalar",
135            "!Cidr mapping",
136            "!Cidr sequence",
137            "!Ref scalar",
138            "!Ref mapping",
139            "!Ref sequence",
140            "!Sub scalar",
141            "!Sub mapping",
142            "!Sub sequence",
143            "!GetAtt scalar",
144            "!GetAtt mapping",
145            "!GetAtt sequence",
146            "!GetAZs scalar",
147            "!GetAZs mapping",
148            "!GetAZs sequence",
149            "!ImportValue scalar",
150            "!ImportValue mapping",
151            "!ImportValue sequence",
152            "!Select scalar",
153            "!Select mapping",
154            "!Select sequence",
155            "!Split scalar",
156            "!Split mapping",
157            "!Split sequence",
158            "!Join scalar",
159            "!Join mapping",
160            "!Join sequence",
161            "!Condition scalar",
162            "!Condition mapping",
163            "!Condition sequence"
164          ]
165        }
166      }
167    }
168  }
169```