How to get VIM matchit plugin working with ColdFusion and HTML?

I am trying to follow the instructions on the vim wiki to get a matchit plugin that works with ColdFusion files (* .cfm) containing ColdFusion and HTML tags that run on MacVim.

I have a syntax file for ColdFusion (cf.vim) set to $ HOME / .vim / syntax / cf.vim, the latest match version set to .vim / plugin / matchit.vim, ve added the following block at the end of the matchit end .vim:

au FileType html,jsp,php,cf if !exists("b:match_words") | 

I also added the following line at the end of my $ HOME / .vimrc file:

 filetype plugin on 

Finally, I added the proposed block at 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 corresponding tag, it only works halfway based on the file extension. If the file has the extension .cfm, I can go from <cfif> to </cfif> , but not from <body> to </body> , for example. The situation is canceled if the extension is .html.

However, looking at the code for cf.vim, it should work with ColdFusion and HTML tags mixed in one 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 

In the corresponding note, I added:

 let b:match_ignorecase = 1 

up to $ HOME / .vimrc to disable case sensitivity as stated in the documentation, but it still only works with cfif, not CFIF.

+4
source share
1 answer

I did something similar for the django template language. I just added the html expressions to b: match_words. For instance. (Note the first three expressions not supporting 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 

These three expressions cover all html / xml, so it is obvious that someone who came up with these three knows a lot more about vime regex than I do.

I would suggest sending the code to vim.org cf.vim if there is no match in the syntax files for cold fusion.

+2
source

Source: https://habr.com/ru/post/1299780/


All Articles