Skip to content

Instantly share code, notes, and snippets.

@jlacar
Last active May 25, 2023 18:52
Show Gist options
  • Save jlacar/00a07453ec4344cf0194 to your computer and use it in GitHub Desktop.
Save jlacar/00a07453ec4344cf0194 to your computer and use it in GitHub Desktop.
Format XML in vi using xmllint

Formatting XML in vi

Using xmllint

You can format XML in vi using xmllint

:%!xmllint "%" --format

Default indentation is 2 spaces. You can change that by assigning a value to the XMLLINT_INDENT environment variable. To do that without leaving vi,

:let $XMLLINT_INDENT="    "

Then just run the same command as before.

Using tidy

If you have tidy installed, you can use it instead of xmllint

:% !tidy -q --input-xml true --indent yes --indent-spaces 4 %
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment