Indent XML/HTML in Vim

Step-by-Step descriptions of how to do things.

Indent XML/HTML in Vim

Postby peter_b » Thu Nov 03, 2016 1:43 am

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)
  • 0

User avatar
peter_b
Chatterbox
 
Posts: 307
Joined: Tue Nov 12, 2013 2:05 am
Reputation: 3

Return to HowTo's

Who is online

Users browsing this forum: No registered users and 1 guest

Who is online over last 24 hours

Users browsed this forum in the last 24 hours: No registered users and 18 guests

cron
Reputation System ©'