LoginSignup
94

More than 5 years have passed since last update.

vimでお手軽にXMLを整形する

Last updated at Posted at 2013-07-20

開発などで改行がないXMLをvimでお手軽に整形するコマンドです。

:%s/></>\r</g | filetype indent on | setf xml | normal gg=G

もしくは

:%s/></>^M</g | filetype indent on | setf xml | normal gg=G

^M^Mの2文字ではなく、Ctrl-Vの後にEnterを入力した1文字です。

インデント不要だったりXMLが巨大で時間がかかる場合は次のように置換だけにすると高速です。

:%s/></>\r</g
:%s/></>^M</g

整形例

<foo><bar><qiita>example</qiita></bar></foo>

こんなテキストが

<foo>
    <bar>
        <qiita>example</qiita>
    </bar>
</foo>

このように整形されます。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
94