Fellow vim users: how are you setting up your vim language for editing Hugo HTML templates? Do you use vim-go or something else? Is there a syntax-highlighting plugin I’m not aware of? I was surprised that syntax highlighting in vim only barely works because Hugo seems like it appeals to a sort of vim / command-line power user, and I know the project has been around for a few years. Maybe the nested syntax is just too gnarly to easily highlight?
There is one vim plugin (vim-hugo-helper) listed on the Hugo editor plugins page which doesn’t do syntax highlighting, and Google hasn’t suggested that other better plugins exist. I know that Hugo uses Go’s html/template, and the vim-go plugin technically does syntax highlighting, but not really — for some reason, only attribute strings are highlighted (i.e. not tags, elements, comments, etc.)
Sorry, I posted my first screenshot above with a pretty dull theme, so it sort of obscured my main point, which is that the Go syntax — e.g. the conditionals — is not being highlighted. You can see this in your screenshot by looking at the conditional at the bottom that’s wrapped around the <figcaption> element.
I just installed Neovim, thanks for the tip. By running nvim-from-vim I was able to use my complete vim plugin & configs as-is by only changing only one line. Thank you!
PS. how did you ID the exact file that code was from so quickly ?
That is some impressive detective work. Sorry to have sent you on a hunt, next time I’ll be sure to reference a more specific code sample. Thanks again for the Neovim suggestion.
Hi @Grob, could you write out the steps go get this to work in (n)vim? Do you have the whole vim-go plugin installed or have you extracted the two relevant files only? Where do you apply your script?
My nvim setup is very close to the default with only a few minor customization. I like to keep things simple, but it would be lovely to get correct syntax highlighting when working with hugo template files!
Thanks @Grob, I got this to work by installing the whole Go plugin and adding your code snippet in init.vim. When I tried adding only the 3 files you mentioned, I got errors however. I can live with having the whole Go plugin installed