我一直在尝试按照
instructions on the Vim wiki来获取matchit插件,使用包含在MacVim上运行的ColdFusion和HTML标记的ColdFusion(* .cfm)文件.
我在$HOME / .vim / syntax / cf.vim中安装了ColdFusion(cf.vim)的语法文件,安装在.vim / plugin / matchit.vim中的matchit的最新版本,我添加了跟随块到matchit.vim结尾:
au FileType html,jsp,php,cf if !exists("b:match_words") |
我还在$HOME / .vimrc文件的末尾添加了以下行:
filetype plugin on
最后,我将建议的块添加到cf.vim的末尾:
" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
finish
endif
" Don't load another plugin for this buffer
let b:did_ftplugin = 1
if exists("loaded_matchit")
let b:match_words = '<cfif\>.\{-}>\|<cfif\>.\{-}$:'
\ . '<cfelseif\>.\{-}>\|<cfelseif\>.\{-}$:'
\ . '<cfelse\>.\{-}>\|<cfelse\>.\{-}$:'
\ . '<\/cfif>,'
\ . '<cfloop\>.\{-}>\|<cfloop\>.\{-}$:'
\ . '<\/cfloop\>.\{-}>,'
\ . '<cfoutput\>.\{-}>\|<cfoutput\>.\{-}$:'
\ . '<\/cfoutput\>.\{-}>,'
\ . '<cftimer\>.\{-}>\|<cftimer\>.\{-}$:'
\ . '<\/cftimer\>.\{-}>,'
\ . '<!---:--->,'
\ . '<cfquery\>.\{-}>\|<cfquery\>.\{-}$:<\/cfquery\>.\{-}>,'
\ . '<cfscript>:<\/cfscript>'
" Since we are counting things outside of comments only,
" It is important we account comments accurately or match_words
" will be wrong and therefore useless
syntax sync fromstart
endif " exists("loaded_matchit")
但是,当我按%键跳转到匹配的标签时,它只有一半工作,基于文件扩展名.如果文件的扩展名为.cfm,我可以从< cfif>跳转到< / cfif>但不是< body>到< / body>例如.如果扩展名是.html,情况就会逆转.
但是看一下cf.vim的代码,它似乎应该与同一文件中混合的ColdFusion和HTML标签一起使用:
" Inherit syntax rules from the standard HTML syntax file
if version < 600
source <sfile>:p:h/html.vim
else
runtime! syntax/html.vim
endif
在相关的说明中,我补充说:
let b:match_ignorecase = 1
到$HOME / .vimrc来禁用案例敏感性,如文档中所述,但它仍然只适用于cfif,而不适用于CFIF.
最佳答案 我为django模板语言做了类似的事情.我刚刚在b:match_words列表中添加了html表达式.例如. (注意前三个非django表情)
if exists("loaded_matchit")
let b:match_ignorecase = 1
let b:match_skip = 's:Comment'
let b:match_words = '<:>,' .
\ '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' .
\ '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,' .
\ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>,' .-
\ '{% *if .*%}:{% *else *%}:{% *endif *%},' .-
\ '{% *ifequal .*%}:{% *else *%}:{% *endifequal *%},' .-
\ '{% *ifnotequal .*%}:{% *else *%}:{% *endifnotequal *%},' .-
\ '{% *ifchanged .*%}:{% *else *%}:{% *endifchanged *%},' .-
\ '{% *for .*%}:{% *endfor *%},' .-
\ '{% *with .*%}:{% *endwith *%},' .
\ '{% *comment .*%}:{% *endcomment *%},' .
\ '{% *block .*%}:{% *endblock *%},' .
\ '{% *filter .*%}:{% *endfilter *%},' .
\ '{% *spaceless .*%}:{% *endspaceless *%}'-
endif
这三个表达式涵盖了所有的html / xml,所以很明显,那些想出这三个的人比我更了解vim正则表达式.
如果冷融合的语法文件中没有matchit,我建议将代码提交给vim.org cf.vim维护者.