11

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 my file to display correct nesting.

Before I tried to use this command I set the file type to xml using :set ft=xml as the file I started with has an extension of .mm, and also :set nowrap.

Here is my ~/.vimrc file:

syntax on
set history=1000
set smartindent
set tabstop=2
set shiftwidth=2
set expandtab

How come when I issue gg=G, I get a message saying 54 lines indented, yet my file remains un-nested?

4

2 回答 2

20

如果你想尝试 Vim 自己的 XML 缩进器,你可以...

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

这将在 $VIMRUNTIME/indent/xml.vim 加载 vimscript

那么当你这样做时

:set indentexpr?        

...它会说 indentexpr=XmlIndentGet(v:lnum, 1)

~~

不过,xmllint 更好,请参阅... http://vim.wikia.com/wiki/VimTip349

我在我的 .vimrc 中有这样方便的键绑定!

" one or more lines:
vmap ,px !xmllint --format -<CR>

" pretty-print current line
nmap ,px !!xmllint --format -<CR>
于 2012-07-26T01:14:00.900 回答
6

尝试输入::set equalprg?。如果它说equalprg=这意味着您没有为 xml 缩进设置程序,那么它可能正在执行一些愚蠢的默认操作。这是将 xmllint 设置为格式化程序的指南:http: //ku1ik.com/2011/09/08/formatting-xml-in-vim-with-indent-command.html

于 2012-07-25T18:02:23.810 回答