Fixing VIM to allow smart match finding using the percent key

Edited the file

/usr/share/vim/vim70/syntax/smarty.vim

Added the following code:

" HTML:  thanks to Johannes Zellner and Benji Fisher.
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>'
endif

This sets the HTML tag matching words for the matchit plug in when the filetype of Smarty is identified.

Then I edited the /etc/vimrc

Adding these lines to the bottom:

" CODE added to universally turn on the matchit plugin.
" added K. Meek 9/09
:source /usr/share/vim/vim70/macros/matchit.vim
:filetype plugin on

Now when you are editing a .tpl file the syntax is “SMARTY” for color coding, but the match words will match HTML tags


So you can position your cursor over say a tag and hit the % key and it will move cursor to the matching tag.  Same with

will find matching

VERY COOL!

You may need the matchit.vim plugin.  You can download it here.

http://www.vim.org/scripts/script.php?script_id=39

This entry was posted in Uncategorized. Bookmark the permalink.

1 Response to Fixing VIM to allow smart match finding using the percent key

  1. beadinsea says:

    Can you offer the match_words to match the smarty part, such as {if}:{/if}?

Leave a Reply

Your email address will not be published.