[vim]在vim中格式化xml

时间:2022-07-10 02:27:20

From: http://blog.sina.com.cn/s/blog_498a6eeb0100v3km.html


在_vimrc中增加:

"  格式化xml
functionXml()
   set filetype=xml
   :%s/></>\r</g"把><替换成>回车<
   :normal gg=G<cr>
endfunction
map <leader>xml  :callXml()



<?xmlversion="1.0"encoding="GB2312"?><xrpc><xrpchead><version>1.0</version></xrpchead><public_req><rpcmode>0</rpcmode><memcache_key></memcache_key><mq></mq><filesvr><fileflag></fileflag><filename></filename><filemd5></filemd5><zipmode></zipmode></filesvr></public_req><transsvr_req><head><transcode>TRANSMSG_QUERY</transcode><oper></oper><orgcode></orgcode><channel>03</channel><chndate>20111007</chndate><chntime>002930</chntime><transdesp></transdesp></head><querymode><maxrecords>10</maxrecords><resultmode></resultmode><filemode></filemode><offset>1</offset><countall>1</countall></querymode><body><DATE_TRANS>20110726</DATE_TRANS></body></transsvr_req></xrpc>

=================>

<?xmlversion="1.0"encoding="GB2312"?>
<xrpc>
 
  <xrpchead>
       <version>1.0</version>
   </xrpchead>
   <public_req>
       <rpcmode>0</rpcmode>
       <memcache_key>
       </memcache_key>
       <mq>
       </mq>
       <filesvr>
           <fileflag>
           </fileflag>
           <filename>
           </filename>
           <filemd5>
           </filemd5>
           <zipmode>
           </zipmode>
       </filesvr>
   </public_req>
   <transsvr_req>
       <head>
           <transcode>TRANSMSG_QUERY</transcode>
           <oper>
           </oper>
           <orgcode>
           </orgcode>
           <channel>03</channel>
           <chndate>20111007</chndate>
           <chntime>002930</chntime>
           <transdesp>
           </transdesp>
       </head>
       <querymode>
           <maxrecords>10</maxrecords>
           <resultmode>
           </resultmode>
           <filemode>
           </filemode>
           <offset>1</offset>
           <countall>1</countall>
       </querymode>
       <body>
           <DATE_TRANS>20110726</DATE_TRANS>
       </body>
   </transsvr_req>
</xrpc>