Indent XML/HTML in Vim

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
peter_b
Chatterbox
Posts: 371
Joined: Tue Nov 12, 2013 2:05 am

Indent XML/HTML in Vim

Post by peter_b »

I've been using vim to beautifully indent XML or HTML files on a daily basis.
Nevertheless, I've stumbled over a new combination of vim-foo by Rajashekar Chintalapati today:
  1. First join all the lines - ggVGgJ
  2. Now break tags to new lines - :%s/>\s*</>\r</g
  3. Now set filetype - :set ft=html (you can do this before too)
  4. Now Indent - ggVG=
Beautiful... :D


The magic spell formula again, in ONE row (just to try being cool):

Code: Select all

ggVGgJ :%s/>\s*</>\r</g :set ft=html ggVG=
8)
Post Reply