indenting XML in vim
Sometimes I need to look inside XML files which consist of one big line. It’s very impossible, and reformatting takes a time. Fortunately, I’ve found a good solution for vim.
I added to my “.vimrc” file:
map <F2> <Esc>:1,$!xmllint --format -<CR>
Now I can press “F2” button, and vim indents the text.
More hints on indenting XML in vim: Tip #349: Format your xml document using xmllint.
May 8th, 2008 at 5:58 pm
Thanks. Quick hit on google and did what I needed.
November 4th, 2008 at 7:51 pm
Thanks, this works great on both linux and mac…
February 24th, 2009 at 5:45 pm
Thanx for the tip. really useful.
March 9th, 2009 at 7:35 pm
Great! This was just what I needed, and with libxml2 from http://sourceforge.net/projects/gnuwin32/ it works fine on Windows too.
March 12th, 2009 at 9:13 am
It works great! Thanks.
May 19th, 2009 at 1:13 pm
Great tip, thanks for that :)
June 26th, 2009 at 7:03 pm
Great, thanks!
July 31st, 2009 at 9:12 pm
Excellent..thanks!
August 4th, 2009 at 11:39 am
cool, thanks
October 21st, 2009 at 9:53 am
Hi, plain great
but what about errors (e.g. not wellformed, or extra chars …).
When they occur. The buffer is overwritten w/ the
errormessage and the original buffercontent is lost
Or do I miss something.
Cheers, Jan
October 22nd, 2009 at 7:04 am
Yes, xml shouldn’t contain errors, otherwise no tool can re-format the document.
January 6th, 2010 at 10:35 am
You can use eclipse and wtp plugin to re-format xml if it is not well formed.
October 13th, 2010 at 5:05 am
Great, Thanks
May 18th, 2011 at 3:36 am
Thanks, very Nice! We can do anything with vim!
December 21st, 2011 at 10:17 pm
awesome, 1st hit and found the answer !
April 20th, 2012 at 12:00 pm
Thanks! First hit and very helpful
August 22nd, 2012 at 8:44 pm
Thx!
August 31st, 2012 at 5:41 pm
Wow….just…wow.