Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change vim indenting format

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?

like image 751
intargc Avatar asked Dec 01 '11 20:12

intargc


People also ask

How do I change the indentation in Vim?

Fix indentation in the whole fileStart in the top of a file (to get there, press gg anywhere in the file.). Then press =G , and Vim will fix the indentation in the whole file. If you don't start in the beginning of the file, it will fix indentation from current line to the bottom of file.

How do I set VI tab to 4 spaces?

Within Vim, type a colon and then "set tabstop=4" which will set the tabs to display as four spaces. Hit colon again and type "set expandtab" which will insert spaces for tabs.

How do I turn off auto indent in Vim?

Globally Disable Auto-Indentation by Disabling the Filevim files (eg. sh. vim ) who set indentexpr option (eg to GetShIndent() ).


1 Answers

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

like image 58
Herbert Sitz Avatar answered Oct 06 '22 06:10

Herbert Sitz