使用gg = G和xml进行Vim格式化 [英] Vim formatting using gg=G with xml

查看:130
本文介绍了使用gg = G和xml进行Vim格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个格式正确的xml文件,并按照此处给出的命令作为答案:

如何在Vim中自动格式化/缩进C代码?

我正在尝试自动缩进文件以显示正确的嵌套.

在尝试使用此命令之前,我已使用:set ft=xml将文件类型设置为xml. 因为我开始使用的文件的扩展名为.mm,并且扩展名为:set nowrap.

这是我的〜/.vimrc文件:

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

为什么在发布gg=G时会收到一条消息,提示54 lines indented,但我的文件仍未嵌套?

解决方案

如果您想尝试使用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>

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?

解决方案

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 -<CR>

" pretty-print current line
nmap ,px !!xmllint --format -<CR>

这篇关于使用gg = G和xml进行Vim格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆