Page 1 of 1

Indent XML/HTML in Vim

Posted: Thu Nov 03, 2016 1:43 am
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)