views:

172

answers:

1

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.

+1  A: 

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)

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

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.

michael