Top

Configuring Vim for Perl 6

October 18, 2008 · Leave a Comment 

Perlsphere: Configuring Vim for Perl 6

I’ve been playing around more with Perl 6 and have started to configure
vim for it. First, download Parrot. After you have built it, change into
the languages/perl6 directory and type make perl6. This will create a
./perl6 executable for you (don’t type make install, though. This causes
problems with future versions, as I’ve discovered).

Next, create the file ~/.vim/syntax/perl6.vim. This should contain Luke
Palmer’s Perl 6 vim syntax file (if there’s a more up-to-date one, please
post a comment). Then, in your ~/.vim/filetype.vim file, add the
following entry:

augroup filetypedetect
autocmd! BufRead,BufNewFile *.p6 setfiletype perl6
augroup END

That will associate any file with a .p6 extension with the Perl 6
filetype. Opening those files in vim will automatically apply the Perl 6
syntax to it.

While you should probably create a Perl 6 plugin, I have a (bad) habit of
just dumping extra stuff in my .vimrc file. In that, I have the following
(you’ll need to adjust your path to the path of the ./perl6 executable):

au! FileType perl6 :call Perl6Mappings()

function! Perl6Mappings()
map r :!~/code/parrot/languages/perl6/perl6 %
endfunction

I’ll likely add more mappings in the future, but for now, this means that
if you type ,r in vim while editing a Perl 6 file (assuming that you use
the comma for your leader), you’ll automatically run the program.

The tests are a bit more difficult. What I’ve done is this:

autocmd! BufRead,BufNewFile *.t call s:PerlTestSetup()

function! s:PerlTestSetup()
let n = 1
let perl5 = 1
if line(”$”) > 500
let nmax = 500
else
let nmax = line(”$”)
endif
while n <= nmax
if getline(n) =~ “use v6″
setfiletype perl6
let perl5 = 0
break
endif
let n = n + 1
endwhile
if perl5 == 1
setfiletype perl
call PerlTestMappings()
endif
endfunc

function! PerlTestMappings()
noremap ,r :!prove -vl %
noremap ,t :!prove -vl %
endfunction

It’s a brute-force check to see if a .t file is Perl 6 or not. It uses a
heuristic and can break. It also doesn’t allow me to run my tests
directly from the editor. It’s a start, though.

Read more from Perlsphere.

Bottom