How to make Vim syntax coloring work for TT templates

Since I'm now doing some serious work with Template Toolkit for the first time, I thought it would be nice to have my editor, Vim, do pretty highlighting of the template code. It makes it easier to read.

Unfortunately Vim doesn't currently (as of version 6.4) have syntax files for TT, but there are some available separately from the site, for TT version 2 templates.

For some reason the files are in DOS format, even in the tarballs (at least in version 0.1.2). If you're not on Windows, convert them to Unix or Mac format by loading each of the two files, doing set ff=unix or whatever, and saving. If you don't do that Vim will get grumpy when it tries to load them. While you're at it, comment out the echo line in tt2.vim, because the message it prints gets in the way when loading files.

Put the two files, tt2.vim and tt2html.vim, your Vim syntax directory. That will probably be ~/.vim/syntax/ under Linux and Unix. The two new filetypes should then be available for you to set with the setf command. For example, you can load a template file and do setf tt2 to just highlight the templating commands, or setf tt2html if you're templating HTML.

To have the file type set automatically for a particular file extension, create a file called something like ~/.vim/ftdetect/tt2.vim and put a line like this in it (changing the .tt extension if you want):

au BufNewFile,BufRead *.tt set filetype=tt2html

For some reason using setf here, as suggested by the install instructions, doesn't seem to work, but setting the filetype option does.

< Providing SSI-like includes for TT in Catalyst | Text::VimColor 0.11 >

Miniblog

(nuggets of inanity)

Tuesday Apr 24th 2007, 16:54 »
Just took the annual web design survey that AListApart do. I don't realy consider myself to be a web designer, but I have been doing a lot of HTML and CSS lately.
Monday Apr 23rd 2007, 18:23 »
Strange, there appears to be a bare-knuckle boxing match going on in the field outside my flat. Wish they wouldn't make so much noise about it.
Thursday Mar 1st 2007, 18:47 »
“In its written form, Hebrew has no vowels, making it the ideal language for texting.”
—Said in jest on some Radio 4 programme just now.

Archive: 2007 · 2006 · 2005 · 2004
Feed