代码片段
使用 snippets: 配置代码片段 操作来创建一个新的代码片段文件或编辑指定作用域的现有代码片段文件。
这些代码片段位于 ~/.config/zed/snippets 目录中,您可以使用 snippets: 打开文件夹 操作导航到该目录。
配置示例
{
// Each snippet must have a name and body, but the prefix and description are optional.
// The prefix is used to trigger the snippet, but when omitted then the name is used.
// Use placeholders like $1, $2 or ${1:defaultValue} to define tab stops.
// The $0 determines the final cursor position.
// Placeholders with the same value are linked.
"Log to console": {
"prefix": "log",
"body": ["console.info(\"Hello, ${1:World}!\")", "$0"],
"description": "Logs to console"
}
}
作用域
作用域由小写的语言名称确定,例如 Python 的 python.json,Shell 脚本的 shell script.json,但此规则也有一些例外情况
| 作用域 | 文件名 |
|---|---|
| 全局 | snippets.json |
| JSX | javascript.json |
| 纯文本 | plaintext.json |
要创建 JSX 代码片段,您必须使用 javascript.json 代码片段文件,而不是 jsx.json,但这不适用于 TSX 和 Typescript,它们遵循上述规则。
已知限制
- 当传入前缀列表时,仅使用第一个前缀。
- 当前仅支持
json代码片段文件格式,即使simple-completion-language-server同时支持json和toml文件格式。
另请参阅
有关更多配置信息,请参阅 simple-completion-language-server 说明。