I develop django templates, and I need to indent them with gg=G
, but jinja2 tags seem to be immune to it. Here is an example of poorly indented, hard to read if-else tags:
{% extends "base.html" %}
{% block content %}
{% load my_tags %}
<center>
<form action="#" method="get">{% csrf_token %}
<input type="text" value="{{ ids }}" name="search_items" size="40">
<input type="submit" value="Search Items">
</form>
{% if searching == True %}
{% if insert_quantity > 0 %}
<br><i>{{ insert_quantity }} from {{ match_quantity }} matches selected:</i><br>
{% item_list items %}
{% else %}
No such items in database.
{% endif %}
{% else %}
<h2>Item List (10 randomly selected)</h2>
{% item_list items %}
{% endif %}
</center>
{% endblock %}
I have installed Glench/Vim-Jinja2-Syntax
, but it does nothing. I also use YouCompleteMe
, which detects and highlights jinja2 syntax (what makes previous plugin redundant?).
Question:
Is it possible to indent those if-else (and for loops) tags with gg=G
with some plugin?
htmldjango
filetype which comes with Vim, and works quite well for Jinja2 in my experience)... You will probably have to do this yourself, by copying the HTML indent file, and modify it so that it recognized Django-style blocks. The file is over 1,000 lines, so this is probably more involved than one or two extra lines... – Martin Tournoij Aug 25 '15 at 15:51<Tab>
key after opening a{% ...
block, an the<Backspace>
when closing one. This works quite well for me... – Martin Tournoij Aug 25 '15 at 15:54