Format XML in VIM

Source: Internet
Author: User

Add the following content to vimrc and then press: PrettyxmlYou can automatically format the XML. However, xmllint must be in your path variable. If you do not have one, please install the libxml2 package.

Function! Doprettyxml ()
"Save The filetype so we can restore it later
Let L: origft = & ft
Set Ft =
"Delete the xml header if it exists. This will
"Permit us to surround the document with fake tags
"Without creating invalid XML.
1 S/ // E
"Insert fake tags around the entire document.
"This will permit us to pretty-format excerpts
"XML that may contain in multiple top-level elements.
0put =' '
$ Put =' '
Silent %! Xmllint -- format-
"Xmllint will insert Header. It's easy enough to delete
"If you don't want it.
"Delete the fake tags
2d
$ D
"Restore the 'normal' indentation, which is one extra level
"Too deep due to the extra tags we wrapped around the document.
Silent % "back to home
1
"Restore The filetype
EXE "set Ft =". L: origft
Endfunction
Command! Prettyxml call doprettyxml ()

This article compiled from http://vim.wikia.com/wiki/Pretty-formatting_XML

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.