Integrating perlcritic and vim

Naturally, you'll need to season this to taste, but here's how I've now integrated perlcritic and vim, making it easy to jump to specific errors.

I've previously written about using the Vi::QuickFix module. It takes advantage of vim's quickfix commands.

First, drop this into your .vimrc:

" quickfix for Perl error formats
set errorformat+=%m\ at\ %f\ line\ %l\.
set errorformat+=%m\ at\ %f\ line\ %l

I also have the following mapping:

noremap ,c :!time perlc --critic %<cr>

It's the perlc hack which makes all of this work.

This hack looks like the following:

Now, if I'm editing something, I can just hit ,c and it will run something like perl -c. Then hitting :cf takes me to the first error, while :cn keeps jumping to the next error, including the perlcritic errors. Note the command line for perlcritic in the program above:

perlcritic --quiet --verbose "%f:%l:%m\\n"

The --verbose flag writes the output into a format that vi's quickfix mode is happy with.

This makes making your programs "perlcritic safe" quick and easy.

About Ovid

user-pic Freelance Perl/Testing/Agile consultant and trainer. See http://www.allaroundtheworld.fr/ for our services. If you have a problem with Perl, we will solve it for you. And don't forget to buy my book! http://www.amazon.com/Beginning-Perl-Curtis-Poe/dp/1118013840/