created January 19, 2004 · complexity basic · author David DelGreco · version 5.7
To run Perl scripts under Windows, you can either add the .pl extension to the PATHEXT environment variable, or use pl2bat, which comes with ActiveState's Perl and makes a very nice batch file. A quirk of Perl under Win32 is that piping doesn't work with .pl files (as in bar.pl | foo.pl) but works fine with the batch files. It has something to do with how Windows loads files. Anyway, this all works fine, but every time I do any extensive edits to a Perl/batch file, I have to set cindent and syntax=perl or it drives me crazy.
To make one change that will apply to any scripts created by pl2bat, edit your user (~/.vim) or machine ($VIMRUNTIME/vimfiles) version of filetype.vim to include a .bat analysis rule:
au BufRead,BufNewFile *.bat if getline(1) =~ '--\*-Perl-\*--' | setf perl | endif
This will cause Vim to scan any .bat files for
--*-Perl-*-- on the first line, and if it's found it will be treated as a Perl file, otherwise the predefined rules for .bat extensions will run.
See :help new-filetype (section C).
You can specify the following text as the first line of the converted file (by manual edit or changing the pl2bat generation) to contain the following to not need to edit the filetype definition. However, this method only applies to each file changed in such a manner.
@rem vim: set ft=perl:
See :help modeline.