views:

368

answers:

3

When editing an html file in vim, the indentation for css inside style tags is messy.

For instance, this is how it would indent this sample css code without any manual intervention to fix the indentation on my part:

    div.class
{
color: white;
       backgroung-color: black;
}

Why is this happening? how can I fix it?

A: 

One explanation might be that you have a mixture of TABs and spaces in the file.

(Although the appearance in the question may be more due to Markdown than anything else)

pavium
I don't have any hard TAB character (and why would it cause messy auto indentation anyway?)
hasen j
A: 

Try using this html filetype indent script instead. It has improved support for style tags. Javascript and CSS indent handling in HTML pages is known to be problematic with the html indentation in Vim. I've yet to find a script that does everything perfectly.

Pierre-Antoine LaFayette
The page says under known bugs "sometimes `cindent()` thinks it is better to use zero indent for what follows", which is pretty much what my problem is.
hasen j
I think the problem is that all these indent files fall back to cindent. It would be nice if someone wrote the entire thing from scratch.
Pierre-Antoine LaFayette
+1  A: 

I experience the same problem, can't really help but I tend to do is vi{ then 9<< and finally >>. I tried to find a good css indent, but none of the ones I tried seemed to work properly.

Plugawy