【问题标题】:How do I get the VIM matchit plugin working with ColdFusion and HTML?如何让 VIM matchit 插件与 ColdFusion 和 HTML 一起使用?
【发布时间】:2010-01-29 22:18:24
【问题描述】:

我一直在尝试关注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 扩展名,我可以从 &lt;cfif&gt; 跳转到 &lt;/cfif&gt;,但不能从 &lt;body&gt; 跳转到 &lt;/body&gt;。如果扩展名为 .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 例如。

【问题讨论】:

    标签: vim syntax plugins coldfusion editor


    【解决方案1】:

    我为 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 维护者。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-20
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 2011-02-07
      相关资源
      最近更新 更多