Golang中如何为tmpl文件配置VsCode语法高亮

Golang中如何为tmpl文件配置VsCode语法高亮 在VSCode中是否有办法高亮显示模板文件(.tmpl)?

{{define "side"}}
    <h3>New Books</h3>
    <p>There's nothing here</p>
{{end}}
4 回复

可能已经存在一个问题。如果没有,请在GitHub项目中创建一个。该项目似乎仍在维护中。

更多关于Golang中如何为tmpl文件配置VsCode语法高亮的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html


如果它与这个扩展相同,那么它无法正常工作。

看看这个扩展:

GitHub GitHub

头像

casualjim/vscode-gotemplate

通过在GitHub上创建账户来为casualjim/vscode-gotemplate开发做贡献。

在VSCode中为.tmpl文件启用语法高亮,可以通过安装适当的扩展或配置文件关联来实现。以下是具体方法:

1. 安装Go Template扩展

推荐安装以下扩展之一:

  • "Go Template" by jbenden
  • "Go Template Snippets" by jbenden

安装后,.tmpl文件将自动获得语法高亮支持。

2. 手动配置文件关联

如果扩展未自动关联,可以在VSCode设置中手动配置:

  1. 打开命令面板(Ctrl+Shift+P)
  2. 输入 “Preferences: Configure File Association”
  3. 选择.tmpl文件
  4. 在语言模式中选择 “Go Template” 或 “HTML”

或者直接在settings.json中添加:

{
    "files.associations": {
        "*.tmpl": "go-template"
    }
}

示例验证

安装配置后,你的模板代码将正确高亮显示:

{{define "side"}}
    <h3>New Books</h3>
    <p>There's nothing here</p>
{{end}}

其中 {{define}}{{end}} 等模板指令和HTML标签都会获得相应的语法着色。

回到顶部