The Gift Of Auto-Completion

A good programmer, just like a good North Pole elf, needs good tools to perform his craft. One of the classics is code snippet auto-completion. The vim editor has a few of them. Two of the best-known ones are snipMate,, inspired by the much liked TextMate editor (, and the newly-emerging UltiSnips (

Up to recently, I only knew (and loved quite dearly) snipMate, but after discovering UltiSnips, I must say that I'm quite impressed by it. ... ah well, there is no point to make you kids wait to unwrap your present: you can go and get it at Yes, it's a snippet file for the whole of Dancer's DSL. Not as exciting as a Rocket-Raptor Sky Armageddon action figure, granted, but much better than a rainbow-colored pullover.

Let's Have Some Milk With Those Cookies

With UltiSnips and the snippet file given above, the whole Dancer DSL is at your fingertip by just issuing the vi command

:UltiSnipsAddFiletypes dancer

Which is awesome. But this is Dancer; awesome is our bread and butter. Can we somewhat make this ultrawesome? Well, how about have UltiSnips discover all by itself if a file is Dancer-related, and active its snippets automatically by adding to our .vimrc:

au BufNewFile,BufRead *.pl,*.pm  call s:detectTypeOfPerl()

fun! s:detectTypeOfPerl()
perl <<EOF
    for ( 0..$curbuf->Count ) {
        if ( $curbuf->Get($_) =~ /use Dancer/ ) {
           VIM::DoCommand(':UltiSnipsAddFiletypes dancer');

Aaaah yes. Just like a little swig of rum in a mug of eggnog, this is making what was already a treat into something truly decadent... Enjoy!


This article has been written by Yanick Champoux for the Perl Dancer Advent Calendar 2012.