Vim 的 XML 文档编辑插件——xml.vim
使用XXE作为DocBook图形化编辑器

取消vim在编辑xml文档时的自动缩进功能

lyanry posted @ 2007年10月18日 03:53 in 开发工具 with tags XML vim , 8022 阅读

我相信很多人也和我一样,在编辑 xml 文档时,本来那一堆 <xxx> ... </xxx> 标记就够让我心烦意乱的了,就更不要说去忍受又臭又长的一串带有缩进的嵌套标记了。所以,我不需要 vim 为 xml 所提供的自动缩进功能。

我们在使用 vim 时,在其配置文件 .vimrc 中,通常有以下设置:

filetype plugin indent on

这一设置实际上是以下三条设置语句的合成:

filetype on
filetype plugin on
filetype indent on

它们的作用分别描述如下:

  1. 打开文件类型检测功能;
  2. 允许VIM加载文件类型插件;
  3. 允许VIM为不同类型的文件定义不同的缩进格式。

对于这几项设置语句更为详细的解释请参考 Easwy 所写的 “使用VIM开发项目”系列文章的 第8篇:开启文档类型检测

本文的主要目的是如何取消 vim 为 xml 文档所赋予的自动缩进功能,而且是在不触动其他文档自动缩进功能的前提下来实现。所以我们只关心 vim 是怎样为不同类型文档提供自动缩进功能的。

如果仔细阅读上文所提到的 Easwy 所写的文章,就会明白 vim 是在 runtimepath 目录的 indent 子目录下找到相应文件类型的自动缩进脚本的。这里所谓的 runtimepath是 vim 默认的一些自动搜索脚本的目录,在 vim 的 normal 模式下输入 :set runtimepath? 可以查看具体的目录。

对于 Linux 系统,vim 自带的一些文件类型的自动缩进脚本文件通常位于 /usr/share/vim/vimcurrent/indent 目录下,若进入该目录,应该可以发现有一个名曰 xml.vim 的文件,只需将这个文件的名字改一下,就可以让 vim 失去对 xml 代码自动缩进的能力了。那么我们就将该文件改成 xml-masked-by-yourname.vim。如果日后心血来潮,需要让 vim 支持 xml 代码自动缩进,可以再把名字改回来。

可能你为了更好的编辑 xml 文档,所以你安装了 xml.vim 插件(见我的另一篇日志)。这样,即使你按照前文那样取消了 vim 对 xml 文档类型的自动缩进支持,但是在使用 xml.vim 提供的自动换行+闭合功能时,依然会自动产生缩进的。我为此郁闷了一个上午,但最后还是找到了解决方法,于是就将取消 xml 缩进进行到底。

方法很简单,打开你所安装的 xml.vim 文件(通常你是将它安装在 $HOME/.vim/ftplugin 目录下的),找到这样一行:

exe "normal 2f>s\<Cr>\<Esc>Ox\<Esc>>>$x"

先将这行代码注释掉,以便于将来恢复。然后在该行代码下面再添加以下代码:

exe "normal 2f>s\<Cr>\<Esc>Ox\<Esc>$x"

实际上,我所做的 hack 只是将原代码中的缩进符号 >> 给去掉了。

现在终于可以舒服地使用 vim 来写 docbook 文档了。

Avatar_small
henry3 说:
2008年2月15日 08:39 这样 tag;; 这种方式,还是缩进了。
Avatar_small
henry3 说:
2008年2月15日 08:47 搞定! 把 L590的 exe 'normal! o^[Ox^[>>$x' 的>>去掉 改为exe 'normal! o^[Ox^[>>$x'
Avatar_small
celebrity heights 说:
2021年6月02日 19:14

Have you ever wonder about any celeb height wiki in real life? You can find all the information you need on this website.

Avatar_small
Robinjack 说:
2023年7月13日 16:29

Regarded this post taking a gander at the space of book once-over applications, and I should say it was an edifying taken out. The maker really got of cross part into the universe of dynamic cycles and gave key information about the best applications that are out there. I saw their assessment as particularly beneficial and material to my drifter pieces since I'm a drawn in peruser with bound time. getAbstract: Book Summaries

Avatar_small
Robinjack 说:
2023年7月13日 16:29

The post acceptably joined the focal parts and functionalities of different book frame applications, uncovering information into their charming liabilities. The creator's wide evaluation, agreed with their own encounters, pulled in me to pick informed choices about which applications change best to my affinities and sorting out targets. They included factors like exactness, watchfulness, and solace, which on a strikingly focal level stayed aware of diminishing the choices. StoryShots: Book Summaries

Avatar_small
Robinjack 说:
2023年7月13日 16:30

If all else fails, the blog part on book outline applications was a certain advantage that left me feeling ready and drawn to check out at this imaginative improvement for figuring out looking at. I respect the maker's wide appraisal and expressive show, as it really expanded my perspective on the need of these applications. I'm right as of now upsetting to impact into the universe of book frame applications and witness firsthand the way that they can change and restore my figuring out process. 12min book summaries

Avatar_small
Robinjack 说:
2023年7月13日 16:31

Likewise, the blog locale limit showed the sensible sorts of progress of book outline applications for perusers of all establishments and interests. The essayist included how these applications could stay aware of one's seeing experience by giving thick yet focused summations, allowing clients to embrace the middle assessments and evaluations of a book without cash the bosses wide time. Headway app

Avatar_small
Robinjack 说:
2023年7月13日 16:31

The post rapidly joined the central parts and functionalities of various book outline applications, revealing data into their picture name liabilities. The maker's concentrated appraisal, related with their own experiences, pulled in me to pick informed decisions about which applications change best to my affinities and sorting out targets. They included factors like accuracy, exactingness, and comfort, which completely remained mindful of diminishing the decisions. Blinkist app

Avatar_small
Robinjack 说:
2023年7月13日 16:31

Respected this post looking at the space of book frame applications, and I ought to say it was an enlightening squashed. The creator worked really of influencing into the universe of fit cycles and gave key data about the best applications that are out there. I saw their evaluation as particularly surprising and material to my necessities since I'm an energized peruser with bound time. apps like blinkist


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter