# 2.1 - 打好基础：YAML格式的学习

插件配置文件一般是 **Yaml** 或者 **Json** 格式，本节就上手难度低，且大部分插件都使用的 **Yaml** 格式的插件配置的基础介绍给大家。

## 大技巧：Yaml 语法格式

**Yaml** 的基本语法格式是 `键: 值`（也就是 `key: value`），例如 `raytrace-distance: 80`。需要注意以下几点：

* 大小写敏感。（由于是插件自动生成的，你也几乎不用考虑点这一点）
* 键与值用 `:` 分开，请注意不是单独的一个 **英文冒号**，而不是一个英文冒号加一个空格。
* 当值中有 `:、&` 等特殊符号时，应该将值的前后用 `'值'` 或者 `"值"` 符号将其囊括，例如 `curse-color: '&c'`。
* 当值中有 `'` 符号时，使用 `''` 代替它，例如 `cannot-afford-type: '&cYou can''t afford to do this! &fCost: &a%cost% %type%'`。（我们可以看到 `can't` 在这里写为 `can''t`）

上面的基本语法格式为普通类型，很多插件中还常用 **List** 类型，它的语法格式为：

```
键:
- 值1
- 值2
- 值3
```

或者

```
键:
  - 值1
  - 值2
  - 值3
```

需要注意的是：

* 第二种表述方法，在其前面仅加了 **2** 个空格。

例如：

```
targets:
  - pickaxe
  - sword
  - axe
  - elytra
  - bow
  - crossbow
  - trident
  - boots
```

### 缩进

无论你是普通类型还是 **List** 类型，你都需要注意一点，就是值也有可能是其他的选项，也就是子选项的缩进。

缩进的一般语法格式为：

```
键1:
  键2: 值1
  键3: 值2
  键4: 
    - 值3
    - 值4
    - 值5
```

键2、键3、键4都在本教程理解为键1的子选项，需要和键1保持 **2** 个空格的距离。

例如：

```
general-config:
  targets:
  - pickaxe
  - sword
  - axe
  - elytra
  - bow
  - crossbow
  - trident
  - boots
  grindstoneable: true
  disabled-in-worlds: []
```

当遇到自己辛辛苦苦编写配置后插件不加载，确定是自己配置的问题以后，就可以检查你的 **Yaml** 语法格式是否正确。

我们可以前往 [这个网站](https://verytoolz.com/yaml-validator.html)，在左边复制好自己的 **Yaml** 文本后点击中间的 **Yaml 验证** 即可，当右边出现 **Valid YAML** 时即代表你的语法格式无误，如下图：

<figure><img src="https://400373137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFlP4xP4pRQ4Bt9AMcMkX%2Fuploads%2Fh4UyImadsBbhdTxdId4r%2F%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE%202022-07-25%20084733.png?alt=media&#x26;token=c04bfd28-2897-495d-bfb5-12ba84b11ecf" alt=""><figcaption></figcaption></figure>

遇到下面这种情况即为有语法错误，并且会将行数告诉你（即 **line 41**，代表第 41 行错误），在这里是因为第 **2** 行缺失另外一个 `'` 符号，导致计算机一直读取到最后也没读到下一个 `'` 符号，所以即在此报错，因此你还需要根据报错的内容来判断是什么问题。

<figure><img src="https://400373137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFlP4xP4pRQ4Bt9AMcMkX%2Fuploads%2FuyO3AlkN24hByUaoXkQm%2F%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE%202022-07-25%20084856.png?alt=media&#x26;token=1e6603bd-32f7-4cca-a233-ddd53c85f1c6" alt=""><figcaption></figcaption></figure>

### 空值

有时插件生成的配置我们根本不想用，但是它自己生成了，删除了又怕插件出问题，这时可以使用空值判断一下我们能否删除它。

在上面所给的示例配置中，出现了大量 `键: []` 的这种情况，这种情况即代表这个配置实际上是可以删除的，删除即使用默认值，一般是空值。在下面的学习之旅中，我们会大量使用空值。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.superiormc.cn/new-user-doc/pei-zhi-de-xue-xi/2.1-da-hao-ji-chu-yaml-ge-shi-de-xue-xi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
