Auto formatting in VIM

6

1

I have a HTML like this:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index - feedman</title>
   <link rel="stylesheet" href="/media/bluetrip/css/screen.css" type="text/css" 
media="screen, projection">
[...]
<body>
    <div class="container">
<div id="greeting">
{% if request.user.is_anonymous() %}
<a href="{{ create_login_url() }}">login</a>
{% else %}
Hello {{ request.user }}! <a href="{{ create_logout_url() }}">logout</a>
{% endif %}
</div>

<p>
{{ message }}
</p>
    </div>
</body>
</html>

How should I automatically format with proper indentation using VIM?

Sridhar Ratnakumar

Posted 2009-10-22T07:10:18.543

Reputation: 4 041

Answers

7

Perhaps you could try : gg=G to indent all the document ? I'm not sure it works good with HTML.

lterrier

Posted 2009-10-22T07:10:18.543

Reputation: 131

Since I didn't have the file saved, I first had to use :set filetype=html – chocojosh – 2011-05-25T15:49:46.683

1

Works brilliantly, I didn't know about the = command to autoindent. You can use https://github.com/othree/html5.vim to add support for HTML5 elements.

– Liam Newmarch – 2012-07-18T15:43:34.290

Works for me. .... – innaM – 2009-10-22T11:16:02.430

0

try to use tidy as explained in the vim tips wiki:

exe 'setlocal equalprg=tidy -quiet -f '.&errorfile

setlocal makeprg=tidy -quiet -e %

akira

Posted 2009-10-22T07:10:18.543

Reputation: 52 754

No tidy please; I wonder if VIM supports this feature at all (that Emacs already has) – Sridhar Ratnakumar – 2009-10-22T10:59:07.863