113
95

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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>

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

113
95
3

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
113
95

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?