gpt4 book ai didi

vim - 你能告诉 Vim 打开一个与命令行或 :e? 传递的文件不同的文件吗

转载 作者:行者123 更新时间:2023-12-02 04:55:27 25 4
gpt4 key购买 nike

我想教 Vim 如何从 File::Find 等名称打开 Perl 5 模块。我已经有一个用 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;

最佳答案

正在做

:verbose au BufReadCmd

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

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

关于vim - 你能告诉 Vim 打开一个与命令行或 :e? 传递的文件不同的文件吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6467225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com