jeanluca has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

Being a lazy programmer I noticed something interesting: perl syntax checking with Vim. What Vim does is check your perl syntax at the moment you try to save it.
Anyway, I assume that almost all vi-perlmonks use this :) so I hope someone can can show me the path ?

This is what I've tried:
I've added to ~/.vimrc
filetype plugin on
I've created the plugin (~/.vim/perl_synwrite.vim) (code)
Finally I create the file ~/.vim/ftplugin and added
~/.vim/perl_synwrite.vim
(I've used the absolute path instead of the ~ as well!)
According to the documentation I should now be able to use the :W option that should do the syntax check and save the file
However, when I try this I get the following message from Vim
E492: Not an editor command: W
Any suggestions what goes wrong here ?

Thanks a lot
LuCa

Replies are listed 'Best First'.
Re: syntax check with Vim
by betterworld (Curate) on Apr 27, 2007 at 12:52 UTC

    This is what I use: Put this into ~/.vim/ftplugin/perl.vim:

    setlocal makeprg=perl\ -c\ %

    Then open your Perl file and type ":make".

Re: syntax check with Vim
by glasswalk3r (Friar) on Apr 27, 2007 at 13:48 UTC

    Maybe you want to check the perl-support plugin for Vim at http://www.vim.org/scripts/script.php?script_id=556. Vim will check sintax by typing \rs inside the editor.

    If you install perltidy things will get even more interesting!

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
      thnx, thats a nice plugin, looks complex, but syntax checking is at least easy. I knew about perltidy, very nice indeed, but the Vim's "Auto complete perl Identifiers" impressed me a lot more :)

      LuCa
Re: syntax check with Vim
by bmann (Priest) on Apr 27, 2007 at 16:35 UTC
    Finally I create the file ~/.vim/ftplugin and added...

    ftplugin should be a directory, not a file.

    Create the directory ~/.vim/ftplugin and put perl.vim there (instead of ~/.vim). The plugin will load automatically now, since you already have filetype plugin on.

Re: syntax check with Vim
by planetscape (Chancellor) on Apr 28, 2007 at 13:44 UTC
Re: syntax check with Vim
by icesmurf (Initiate) on May 01, 2007 at 05:42 UTC
    Personally, i have it setup so that i can do the following, pressing CTRL-K executes a set command whenever i press it, for perl files, it does a syntax check :
    map <C-K> :call SyntaxCheck()<CR> function! SyntaxCheck() let filename = expand("%") let ftype = &filetype if ftype == '' return echo ftype elseif ftype == "cs" if exists("Makefile") let cmd = "!clear; make" else let cmd = "!clear; mcs --parse " . filename endif echo cmd execute cmd elseif ftype == "perl" let cmd = "!clear; echo \"\"; echo \"\"; perl -cw " . +filename echo cmd execute cmd elseif ftype == "javascript" let cmd = "!clear; echo \"\"; echo \"\"; smjs " . file +name echo cmd execute cmd else echo "Cant syntax check file type : " . ftype return endif endfunction
Re: syntax check with Vim
by guiwp (Sexton) on Jun 14, 2016 at 16:45 UTC
    Does anybody knows if there is anything ready to use with Vundle?