w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
.vimrc to automatically compile perl code, based on actual perl version

You have to dynamically change the Perl path in 'makeprg' based on the shebang line. For example:

:let perlExecutable = matchstr(getline(1), '^#!zsS+')
:let perlExecutable = (empty(perlExecutable) ?
'/home/utils/perl-5.14/5.14.1-nothreads-64/bin/perl' : perlExecutable) "
Default in case of no match
:let &makeprg = perlExecutable . ' -c % $*'

You can invoke that (maybe encapsulated in a function) on the FileType event, but then it won't properly detect new files that don't have the shebang yet. Or prepend the call to your autocmd BufWritePost *.pl,*.pm,*.t :make; that will re-detect after each save.


PS: Instead of all those :autocmd FileType in your ~/.vimrc, I would rather place those in ~/.vim/after/ftplugin/perl.vim (if you have :filetype plugin on). Also, you should use :setlocal instead of (global) :set.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.