如何让 VIM matchit 插件与 ColdFusion 和 HTML 一起使用?
我一直在尝试按照 Vim wiki 上的说明 来使用 matchit 插件ColdFusion (*.cfm) 文件包含在 MacVim 上运行的 ColdFusion 和 HTML 标签。
我已经在 $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 扩展名,我可以从
跳转到 ,但不能从
跳转到例如
。如果扩展名是 .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。
I've been attempting to follow the instructions on the Vim wiki to get the matchit plugin working with ColdFusion (*.cfm) files containing both ColdFusion and HTML tags running on MacVim.
I've got the syntax file for ColdFusion (cf.vim) installed in $HOME/.vim/syntax/cf.vim, the latest version of matchit installed in .vim/plugin/matchit.vim, and I've added the following block to the end of the end of matchit.vim:
au FileType html,jsp,php,cf if !exists("b:match_words") |
I also added the following line to the end of my $HOME/.vimrc file:
filetype plugin on
Finally I added the suggested block to the end of 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")
However when I press the % key to jump to the matching tag it only half works, based on the file extension. If the file has a .cfm extension I can jump from <cfif>
to </cfif>
but not <body>
to </body>
for example. The situation is reversed if the extension is .html.
However looking a the code for cf.vim it appears that it should work with ColdFusion and HTML tags mixed in the same file:
" Inherit syntax rules from the standard HTML syntax file
if version < 600
source <sfile>:p:h/html.vim
else
runtime! syntax/html.vim
endif
On a related note I added:
let b:match_ignorecase = 1
to $HOME/.vimrc to disable case sensitivity as stated in the documentation, but it still only works with cfif and not CFIF for example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 django 模板语言做了类似的事情。我刚刚在 b:match_words 列表中添加了 html 表达式。例如。 (注意前三个非 django 表达式)
这三个表达式涵盖了所有 html/xml,所以显然无论是谁提出这三个表达式,都比我更了解 vim 正则表达式。
如果冷聚变的语法文件中没有匹配项,我建议将您的代码提交给 vim.org cf.vim 维护者。
I did something similar for the django template language. I just added the html expressions in the b:match_words list. Eg. (Note the first three non django looking expressions)
Those three expressions cover all of html/xml so obviously whoever came up with those three know a lot more about vim regex than I do.
I'd suggest submitting your code to the vim.org cf.vim maintainer if there is no matchit in the syntax files for cold fusion.