Vim has a package called Matchit, which helps you jump from tag to tag using '%' key. This is quite helpful in html files, since you can jump from the starting to ending , as well as starting '<' to ending '>'. It seems that the way tag jumping works is that it changes from language to language. The above behaviour is stopped in a javascript file, and the jumping occurs on (), {} tags and so on.
I have the following problem:
I have a .tpl file, which contains both html and javascript, but % tag jumping for html elements doesn't work anymore. How can I enable mixed behaviour - html style jumping & js style jumping? Thanks.
The %
jumping to ()
, {}
, []
is based on the built-in 'matchpairs'
option. The matchit plugin builds upon that and allows more complex jumps (like HTML tags).
As the HTML filetype just extends the 'matchpairs'
option, you can just use that filetype, also for mixed-mode files. (Many HTML files contain JavaScript snippets, anyway, so that's a well-supported combination.)
For me, *.tpl
is by default detected as filetype=smarty
. This filetype (in Vim 8.1) only supplies a syntax script, but no filetype settings.
You can inherit the HTML filetype settings (which include the matchit definitions) by creating ~/.vim/ftplugin/smarty.vim
:
if exists('b:did_ftplugin') | finish | endif
runtime! ftplugin/html.vim
runtime! ftplugin/html_*.vim ftplugin/html/*.vim
let b:did_ftplugin = 1