home ~ socials ~ projects ~ rss

Add Jinja Syntax Highlighting To Neovim

April 2023

I'm using the Minijinjamj Rust crate to make the templates for Neopolitanneo. It's a solid format but it's a bit hard to look at. Especially without syntax highlighting which doesn't appear to be available by default in Neovimg:nvim.

I tried a pluginplug to add the highlights but caused a bunch of errors every time I started up.

This is the process I ended up going with:

  1. Create the directory:

    ~/.config/nvim/syntax

  2. Download the jinja.vim 1.1 and htmljinja.vim 1.0 files from this page and put them in the syntax directory
  3. Make a new file at:

    ~/.config/nvim/syntax/synload.vim

    and put this in it:

au Syntax jinja   runtime! syntax/htmljinja.vim
au BufNewFile,BufRead *.jinja,*.j2  setf jinja

That got syntax highlighting working for me. It doesn't do automatic indention. That would be nice but if I had to choose one or the other I'd choose syntax highlighting over the indention.

I've forked the other repo so can take a look at it as well.

Notes

  • The plugin with the errors is two years old so I'm not surprised it has problems
  • The syntax files are closer to 20yrs old, but thankfully they still work just fine
end of line

References

Footnotes

"a powerful template engine for Rust with minimal dependencies"

My plain-text format for websites

The "hyperextensible Vim-based text editor" that's my daily driver. (Though I'm not picky, I use VSCode, Sublime Text, and Emacs too)

This is the plugin I tried that kinda worked but threw a bunch of errors.

Share link:
https://www.alanwsmith.com/en/2o/xn/vi/ry/?add-jinja-syntax-highlighting-to-neovim