Vim indent xml file

后端 未结 9 1812
北恋
北恋 2020-12-07 08:05

I am learning Vim but I thought this was a simple task but I cannot get it to work. I have browser SO but the solutions are not working for me.

I am trying to correc

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 08:28

    Use an external program to indent your xml files. In this case I've choosen xmllint, so set the command to the equalprg option:

    :set equalprg=xmllint\ --format\ -
    

    Now you can execute

    gg=G
    

    to let xmllint format your xml files.

    To get it every time you use vim, use an autocommand to set it.

    autocommand from a comment below

    au FileType xml setlocal equalprg=xmllint\ --format\ --recover\ -\ 2>/dev/null
    

提交回复
热议问题