Note
This is intended to be kept as a proof of concept, please adapt the example to your specific situation
Editing Go template files (.tmpl) in Neovim lacks accurate syntax highlighting, making the code harder to read and maintain.
This plugin adds treesitter support to separate go template syntax from the host language syntax. It
is very simple for now, it checks the file name ends with a format like .$FT.tmpl
, then sets it as
@injection.language = $FT
for treesitter.
-- lazy.nvim --
{ "ngynkvn/gotmpl.nvim", opts = {}}
Once installed, Treesitter will automatically highlight Go template files. Simply open a .tmpl file, and you should see improved syntax highlighting. If your file type isn’t detected correctly, you can manually set it:
:set filetype=gotmpl