6

I want to add to the way html is indented in vim. I'm doing django development and I would like to indent whenever a django template tag is used. Currently, using filetype indent, it does not indent after the template tags. So currently my code looks like this:

{% do_something %}
<div>
  <p>Hello</p>
</div>
{% end %}

And I'd like for it to recognize the {% %} as a tag and indent like so:

{% do_something %}
  <div>
    <p>Hello</p>
  </div>
{% end %}

Is there a filetype plugin for this or a way I can add {% %} to the list of things that should be indented after?

intargc
  • 3,051
  • 5
  • 36
  • 52

2 Answers2

1

When you have filetype indent on for an html file it will use the indenting rules found in the ../vim/vim73/indent subdirectory in file html.vim.

The braces you want to use as signaling indent of next line are, I'm sure, not treated in html.vim because they're not part of html. You can alter the rules in html.vim to get it done the way you want.

See :h indent-expr for a bit of info and you will also want to look at other files in the /indent directory to see how it works.

There is an alternate html.vim you can get at vim website, maybe it is better than html.vim that ships with Vim: http://www.vim.org/scripts/script.php?script_id=2075

Herbert Sitz
  • 21,858
  • 9
  • 50
  • 54
  • Also see: http://stackoverflow.com/questions/4829244/how-do-i-define-indents-in-vim-based-on-curly-braces – user606723 Dec 01 '11 at 20:17
  • Both of the html plugins expect specific tag names to determine the indent. Being that django tags can be infinite and unpredictable since you can write your own, I'm not exactly sure how to leverage these plugins to do this... On top of that, any tags that have a body always have an {% endwhatever %} closing tag. I was hoping this would be a quick fix but instead it looks like it would take a lot of effort since I'm not very familiar with it all to begin with... Thanks for steering me in the right direction though! – intargc Dec 01 '11 at 21:09
0

There is a pending pull request for the django.vim project to include an alternative django-custom vim implementation from Steve Losh. This works, for the most part, better than the default one.

Hans Kristian
  • 1,786
  • 19
  • 25