您能告诉Vim打开一个不同于命令行或:e的文件吗?

Cha*_*ens 4 vim

我想教Vim如何从名称打开Perl 5模块File::Find。我已经有一个用Perl 5编写的可处理命令行的包装脚本(请参见下文),但是我希望能够说出类似的东西:tabe File::Find并使其真正执行:tabe /home/cowens/apps/perlbrew/perls/perl-5.14.0/lib/5.14.0/File/Find.pm

我当前的计划是以某种方式使用autocmd BufNewFile和/或autocmd BufPreRead,但是我不知道如何切换文件名。

#!/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;
Run Code Online (Sandbox Code Playgroud)

seh*_*ehe 5

在做

:verbose au BufReadCmd
Run Code Online (Sandbox Code Playgroud)

会告诉您其他类型的插件如何执行此操作(例如zip,netrw,逃犯)。示例输出应该给您很多想法:

zip  BufReadCmd
    zipfile:* call zip#Read(expand("<amatch>"), 1)
    Last set from C:\Program Files\Vim\vim73\plugin\zipPlugin.vim
    *.zip     call zip#Browse(expand("<amatch>"))
    Last set from C:\Program Files\Vim\vim73\plugin\zipPlugin.vim

Network  BufReadCmd
    ftp://*   exe "silent doau BufReadPre ".fnameescape(expand("<amatch>"))|call netrw#Nread(2,expand("<amatch>"))|exe "silent doau BufReadPost ".fnameescape(expand("<amatch>"))
    Last set from C:\Program Files\Vim\vim73\plugin\netrwPlugin.vim
    http://*  exe "silent doau BufReadPre ".fnameescape(expand("<amatch>"))|call netrw#Nread(2,expand("<amatch>"))|exe "silent doau BufReadPost ".fnameescape(expand("<amatch>"))
    Last set from C:\Program Files\Vim\vim73\plugin\netrwPlugin.vim

fugitive_files  BufReadCmd
    *.git/index
              exe s:BufReadIndex()
    Last set from C:\Program Files\Vim\vimfiles\plugin\fugitive.vim
    *.git/*index*.lock
              exe s:BufReadIndex()
    Last set from C:\Program Files\Vim\vimfiles\plugin\fugitive.vim
    fugitive://**//[0-3]/**
              exe s:BufReadIndexFile()
    Last set from C:\Program Files\Vim\vimfiles\plugin\fugitive.vim
    fugitive://**//[0-9a-f][0-9a-f]*
              exe s:BufReadObject()
    Last set from C:\Program Files\Vim\vimfiles\plugin\fugitive.vim
Run Code Online (Sandbox Code Playgroud)