I want to teach Vim how to open Perl 5 modules from names like File::Find. I already have a wrapper script written in Perl 5 that handles the commandline (see below), but I would like to be able to say things like :tabe File::Find and have it really execute :tabe /home/cowens/apps/perlbrew/perls/perl-5.14.0/lib/5.14.0/File/Find.pm.
My current plan is to somehow use autocmd BufNewFile and/or autocmd BufPreRead, but I can’t figure out how to switch the file name.
#!/usr/bin/perl
use strict;
use warnings;
my @files = @ARGV;
for my $file (@files) {
next if -f $file; #skip files that really exist
#convert from module name to module file
(my $module = $file) =~ s{::}{/}g;
$module .= ".pm";
#look for module in the include paths
for my $dir (@INC) {
my $candidate = "$dir/$module";
if (-f $candidate) {
$file = $candidate;
last;
}
}
}
#replace this script with vim
exec "vim", "-p", @files;
Doing
Will tell you how other types of plugins do this (e.g. zip, netrw, fugitive). Sample output that should give you plenty of ideas: