E
E
edem2012-07-14 01:56:18
vim
edem, 2012-07-14 01:56:18

How to properly set up Template Toolkit syntax highlighting in Vim?

Here is a Vim script www.vim.org/scripts/script.php?script_id=830 that does this. I added it to the syntax folder, added the necessary lines to filetype.vim:

au BufNewFile,BufRead *.tt2 call s:AdjustTT2Type()

func! s:AdjustTT2Type()
    if ( getline(1) . getline(2) . getline(3) =~ '<\chtml'
              && getline(1) . getline(2) . getline(3) !~ '<[%?]' )
       || getline(1) =~ '<!DOCTYPE HTML'
        setf tt2html
    else
        setf tt2
    endif
endfunc

To define START_TAG and END_TAG you like, you can set any pair of tags to 'b:tt2_syn_tags':
    "ASP"
    :let b:tt2_syn_tags = '<% %>'
    "PHP"
    :let b:tt2_syn_tags = '<? ?>'
    "TT2 and HTML"
    :let b:tt2_syn_tags = '\[% %] <!-- -->'

everything highlights, norms, but in one point there is a bug. When we use the range operator [... ] (and indeed any square brackets), it stops at them and perceives all subsequent code as tt, not as html.
<html>
<body>
<ul>
[% FOREACH num IN [1..10] %]
<li>num: [% num %]</li>
[% END %]
</ul>
</body>
</html>

starting with the line "IN [1...." there are jambs. Maybe one of you knows how to fix this?
PS and if you open a file from the NERDTree file list, then it generally recognizes it as plain text ...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question