2005-06-01

Software: Vim HTML Pretty Indentation

I initially wrote lots of dummy HTML table rows like this:
<table>
<tr><td>Blah</td><td>Blah</td></tr>
</table>
As the text in the table cells grew longer, the rows became harder to read and edit because they were wrapped over more than one line. So, I inserted a carriage return between every end and start tag. In vim, the command :%s/></>Control-Q Control-M/g< results in:
<table>
<tr>
<td>Blah</td>
<td>Blah</td>
</tr>
</table>
Still ugly. Now I want to prettify the text with indentation. I found tip 83. So, I moved the cursor to the start of the file, typed =G and got this:
<table>
  <tr>
    <td>Blah</td>
    <td>Blah</td>
  </tr>
</table>
Ahh, the power of vim!

No comments:

Post a Comment