Monday, May 13, 2013

VTL - Velocity Template Language syntax highlighter + filetype plugin for Vim

In the beginning of 2012 I created Velocity Template Language plugin for Vim. This post is meant to be no more than to bind everything together and bring it to one place. The plugin itself can be found on or on github. The description is taken from page and is posted below unchanged.

An example of vtl file syntax highlighting with the colors I use looks like:

This is a Velocity Template Language syntax highlighter + filetype plugin. It features support of shorthand $my.some.reference(something) and longhand ${my.some.reference(something)} notations for both references and directives (including user defined macros). Everything described on the official web page ( is supported. Supports directives along with user defined macros one line and multiline. Error handling of incorrectly placed directives. References can be mutliline, so that

$myref.long.array[ 3 ].

is also supported. Directives and references' methods and arrays can contain comments, unformatted text and doxygen comments.

Special references sequences (e.g. $foreach.parent.index or $foreach.topmost.hasNext) are recognized as keywords if they are contained.

Two types of strings are supported. References inside double quotes "" are highlighted.

Matchit support is introduced which allows you to jump from the start of a block (i.e. #if(), #foreach(), #define(), #macro(), #@any_user_macro()) to the end of the block (#end | #{end}) and vice versa with % just like you jump between opening and closing brackets.

Also all multiline directives supports folding.

Only directives described on the official web-page are recognized as system directives, user defined directives are recognized differently and can be one line or multiline.

Comments are automatically expanded to the next line while a user types them and appropriately recognized by vim engine.

NOTE: this differs from velocity.vim ( in many cases, which provides only basic capability, which doesn't include recogniton of multiline entities. It doesn't support system directives and error handling. No way to jump between openinig and closing directive. No support of nonparsable blocks. That script is really very basic (no offence to the author).

This one provides all the capabilites described on the official web-page (
install details
unpack to ~/.vim, or install pathogen.vim and unpack to ~/.vim/bundle/vtl

to make the sytax highlighting and ftplugin work appropriately one may need to add
autocmd BufRead,BufNewFile *.vm set syntax=vm filetype=vm
to his/her ~/.vim/ftdetect/syntax.vim