Vim formatting using gg=G with xml

前端 未结 2 1995
心在旅途
心在旅途 2021-02-05 22:24

I have a correctly formatted xml file, and following the command given as an answer here:

How can I autoformat/indent C code in vim?

I am trying to auto indent

2条回答
  •  甜味超标
    2021-02-05 23:02

    in case you wanna try Vim's own XML indenter thing, you can...

    :filetype indent on         (load indent files for specific file types etc.)
    :e                          (to reload the current buffer)
    

    this will load the vimscript at $VIMRUNTIME/indent/xml.vim

    then when you do

    :set indentexpr?        
    

    ...it'll say indentexpr=XmlIndentGet(v:lnum, 1)

    ~~

    xmllint is better though, see... http://vim.wikia.com/wiki/VimTip349

    i have handy keybinding like this for it in my .vimrc!

    " one or more lines:
    vmap ,px !xmllint --format -
    
    " pretty-print current line
    nmap ,px !!xmllint --format -
    

提交回复
热议问题