Lexima is great, but does not include any rules for web templates, so I wrote
some. Then I figured other people might find them useful, so I pulled them out of my init.vim
and here they are.
Use your favorite plugin manager. I like Vim-Plug. You must have Lexima.
In all cases below, |
represents the cursor position.
For all templates, including plain HTML and XML:
Before Input After
----------------------------------------------------------------------------
| < <|>
----------------------------------------------------------------------------
<|> or <|/> <Backspace> |
----------------------------------------------------------------------------
<tag>| or <tag/>| <Backspace> <tag|> or <tag|/>
----------------------------------------------------------------------------
<tag foo="bar"|> / <tag foo="bar"/>|
----------------------------------------------------------------------------
<tag|/> / <tag/>|
----------------------------------------------------------------------------
<tag>|</tag> <Enter> <tag>
|
</tag>
----------------------------------------------------------------------------
For Django, Jinja2, Twig and Liquid templates (as appropriate):
Before Input After
----------------------------------------------------------------------------
{|} % or # {%|%} or {#|#}
----------------------------------------------------------------------------
{%|%} - {%-|-%}
----------------------------------------------------------------------------
{%|%} <Space> {% | %}
----------------------------------------------------------------------------
{%-|-%} <Space> {%- | -%}
----------------------------------------------------------------------------
{%- | -%} <Backspace> {%-|-%}
----------------------------------------------------------------------------
{% | %} <Backspace> {%|%}
----------------------------------------------------------------------------
{%-|-%} <Backspace> {%|%}
----------------------------------------------------------------------------
{%|%} <Backspace> {|}
----------------------------------------------------------------------------
{{ foo| }} or {{ foo |}} } {{ foo }}|
----------------------------------------------------------------------------
{{ foo }}| <Backspace> {{ foo| }}
----------------------------------------------------------------------------
{% tag| %} % or } {% tag %}|
----------------------------------------------------------------------------
{% tag %}| <Backspace> {% tag| %}
----------------------------------------------------------------------------
{% if foo %}| <Enter> {% if foo %}
|
{% endif %}
----------------------------------------------------------------------------
For Mako templates:
Before Input After
----------------------------------------------------------------------------
<%def name="foo">| <Enter> <%def name="foo">
|
</%def>
----------------------------------------------------------------------------
% for foo in bar:| <Enter> % for foo in bar:
|
% endfor
----------------------------------------------------------------------------
<%| or <%!| <Enter> <% or <%!
|
%>
----------------------------------------------------------------------------
<%inheri|> t <%inherit|/>
----------------------------------------------------------------------------
<%namespace|/> <Backspace> <%namespac|>
----------------------------------------------------------------------------
There are rules for the following template systems:
If there are other template systems with syntax similar to that of any of the above, I will be glad to add them to these rules (or accept pull requests).
In Jinja2 and Twig templates, I rarely use set
blocks. By default, these rules will not add {% endset %}
for you. If
you want endset
s added, let g:lexima_template_rules_endset = 1
in your .vimrc
or init.vim
.