问题描述
我正在学习 Vim,但我认为这是一项简单的任务,但我无法让它工作.我有浏览器,但解决方案对我不起作用.
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.
我正在尝试正确缩进文件 (xml).我使用的命令是:
I am trying to correctly indent an file (xml). The command I use is:
gg=G
或ggVG=(我自己编的,可能做了一些不同的事情;))
or ggVG= (made this one up myself probably does something different ;))
我的 .vimrc 是:
My .vimrc is:
syntax on
filetype plugin indent on
set nu
推荐答案
我喜欢 Berei 的回答.但是,我认为以下更灵活一点,因为您不必更改 vimrc
文件.此外,格式化 XML 文件的选定部分更容易(我碰巧经常这样做).
I like Berei's answer. However, I think the following is a little more flexible in that you don't have to alter your vimrc
file. Plus it is easier to format select portions of the XML file (something I happen to do a lot).
首先,突出显示要格式化的 XML.
First, highlight the XML you want to format.
然后,在普通模式下,输入 !xmllint --format -
Then, in normal mode, type ! xmllint --format -
底部的命令行如下所示:
Your command-line at the bottom will look like this:
:'!xmllint --format -
然后按回车键.
选中的文本发送到xmllint
命令,然后--format
'ed,xmllint
的结果放在你的vim 中的选定文本.命令末尾的 -
用于接收标准输入 - 在这种情况下,它是 vim 发送到 xmllint
的选定文本.
The selected text is sent to the xmllint
command, then --format
'ed, and the results of xmllint
are placed over your selected text in vim. The -
at the end of the command is for receiving standard input - which, in this case, is the selected text that vim sends to xmllint
.
这篇关于Vim 缩进 xml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!