Getting Vim to recognize XML

后端 未结 3 1400
悲哀的现实
悲哀的现实 2020-12-14 18:34

I would like Vim to help me indent my XML files like my C code. However, when I use

gg=G

It just sets everything to the left. Do I need to

相关标签:
3条回答
  • 2020-12-14 18:37

    Put

    filetype plugin indent on
    

    in your .vimrc to have Vim automatically identify .xml files as xml. You might need to put

    set nocompatible
    

    before that.

    If the file extension is not .xml, you can make Vim threat it like xml by using

    :set filetype=xml
    

    After you do that, Vim's autoindention (and syntax highlighting, and omnicomplete (that in xml just closes tags, but that's still something)) will work properly for xml.

    0 讨论(0)
  • 2020-12-14 18:37

    add this line to your .vimrc file:

    :map <Space>fx :%s/\ </\r</g<cr>:%s/\ android/\randroid/g<cr>:g/^$/d<cr>gg=G`
    

    to format click space fx

    0 讨论(0)
  • 2020-12-14 19:03

    Yep, :set syntax=xml should work. In vim 7.3, this sets :set indentexpr=XmlIndentGet(v:lnum,1).

    If you've got a one-line file, you may need to :%s/\(<[^>]*>\)/\1\r/g, to insert newlines after every tag (or split it differently).

    Then, gg=G should work.

    0 讨论(0)
提交回复
热议问题