Whenever I create html file with jinja
code from terminal either using shell commands or directly using vim
, the file type is always set to html
and not jinja.html
, which causes number of issues like jinja
files not being syntax highlighted, snippets do not show up in completion popups.
I am using Glench/Vim-Jinja2-Syntax
for jinja syntax highlighting. I do understand this plugin might be looking for certain keywords in the file to associate the file as jinja.html
file. Even if I create a file like below in Vim
, save it , close it with :wq
and then open it again, still the file type is html
only.
{% extends "base.html" %}
{% block body %}
{% endblock %}
This is what set filetype?
reports filetype=html
.
However if I create the same file with some IDE like PyCharm
or VsCode
this does not happen, and after that if I open the file in Vim
, then it sets the correct file type as jinja.html
. My guess is PyCharm
and VsCode
might be adding some metadata to the file while creating the file which Vim is not doing when the file is created by Vim but I am not sure about this..
Another weird thing that I noticed, say I create a file named dummy.html
with above jinja
code with Vim
and then save+close it, obviously Vim
isn't setting the correct file type for it. Now the weird, even if I delete this file and then recreate it in PyCharm
with same name i.e. dummy.html
and load in Vim
, Vim
fails to set the correct file type.
I tested this multiple file names, means I created the file in Vim
and then delete it and then create the file with same name in PyCharm
and Vim
does not set the file type. However if I use a new name while creating the file in PyCharm
, a name which I haven't used while creating file with Vim
, then Vim
file sets the file type correctly to jinja.html
.
So can anyone please help me how can I fix this. I apologize if the issue description is bit confusing but this issue is so weird that honestly I am not sure how to better the description.
Glench/Vim-Jinja2-Syntax
plugin and created your example file. At first it was detected ashtml
, as it has no content. After writing and:e!
or on reopen Vim, it was detected asjinja.html
and the filetype was correct. Tested on Vim 8.1.885 on Linux. I would recommend to strip down your Vim setup to only containVim-Jinja2-Syntax
and test again.