需求:
1,当用gvim打开一个后缀名为.log的文件时,先对文件进行一些处理,比如删除一些字符,然后再显示在gvim里面
这种功能大概怎么个思路,然后已经写好对应的处理脚本,但是用perl写的,想问gvim做类似的功能有什么文档可以参考一下,谢谢哈
如何开发vim的小脚本
-
- 帖子: 6
- 注册时间: 2010-09-11 16:26
- 系统: win8.1
- 联系:
如何开发vim的小脚本
[url]http://jd170.net,关注虚拟运营商,关注170号码[/url]
- acer4740
- 帖子: 1405
- 注册时间: 2010-09-13 19:04
- 来自: 0xFF00EE
Re: 如何开发vim的小脚本
代码: 全选
augr ui
au!
au bufreadpost,filereadpost *.ui exe "%!python ".expand("<sfile>:p:h:gs?\\?/?")."/pyuic.py %"
au bufreadpost,filereadpost *.ui set ft=python
augr END
这是我用python写的一个,perl的自己改一改吧
- acer4740
- 帖子: 1405
- 注册时间: 2010-09-13 19:04
- 来自: 0xFF00EE
Re: 如何开发vim的小脚本
代码: 全选
augr ui
au!
au bufreadpost,filereadpost *.log exe "%!perl ".expand("<sfile>:p:h:gs?\\?/?")."/script.pl %"
au bufreadpost,filereadpost *.log set ft=log
augr END
- acer4740
- 帖子: 1405
- 注册时间: 2010-09-13 19:04
- 来自: 0xFF00EE
- Fermat618
- 帖子: 728
- 注册时间: 2008-12-28 16:01
-
- 帖子: 6
- 注册时间: 2010-09-11 16:26
- 系统: win8.1
- 联系:
Re: 如何开发vim的小脚本
哈哈,不好意思哈Fermat618 写了:这标题起得真不对内容,搞得我又重新把这帖子看了一遍。
[url]http://jd170.net,关注虚拟运营商,关注170号码[/url]
-
- 帖子: 151
- 注册时间: 2009-05-29 22:05
Re: 如何开发vim的小脚本
你学perl当然是看:h if_perl
我也懒得学vim脚本,这是我写的两个小功能:
注释用:
打开XP的资源管理器并切换到当前buffer所在位置,也可以打开getcwd()后的那个目录或者指定的目录也行
我也懒得学vim脚本,这是我写的两个小功能:
注释用:
代码: 全选
"<==================================================
" comment region
"<==================================================
if has("perl")
function! Commenter()
perl comment_region();
endfunction
silent vmap <c-j> <esc>:call Commenter()<cr>
perl << EOF
sub comment_region{
my $curbuf = $main::curbuf;
my $file_extension = (split/\.|_/,$curbuf->Name())[-1];
my %comment=(
"pl"=>"\#",
"pm"=>"\#",
"vimrc"=>"\"",
"vim"=>"\"",
);
my ($success, $startline) = VIM::Eval('getpos("\'<")[1]');
my ($success, $endline) = VIM::Eval('getpos("\'>")[1]');
my @text= $curbuf->Get($startline..$endline);
for my $item(@text){
if (exists $comment{$file_extension}){
if($item=~/^((?:(?:\s+))?$comment{$file_extension}+)+/){
$item=~s/$1//;
}
else{
$item=~s/^/$comment{$file_extension}/g ;
}
}
else{
VIM::Msg("该类型文件的注释符号未定义","ErrorMsg");
last;
}
}
$curbuf->Set($startline, @text);
}
EOF
endif
代码: 全选
"<==================================================
"open in file explorer when in xp
"<==================================================
if has("perl")
function! OpenFileExplorer(...)
perl open_explorer();
endfunction
command -bar -nargs=* -complete=file OpenFileExplorer call OpenFileExplorer(<q-args>)
perl <<EOF
sub open_explorer{
my $curbuf = $main::curbuf;
my $args = VIM::Eval('a:1');
if($args eq ""){
my $dir = VIM::Eval('expand("%:p:h")');
\&check_sys(\$dir);
}
elsif($args eq "pwd"){
my $dir = VIM::Eval('getcwd()');
\&check_sys(\$dir);
}
else{
if (-e $args){
\&check_sys(\$args);
}
else{
VIM::Msg("目录不存在!请检查输入是否有误。","ErrorMsg");
}
}
}
sub check_sys{
my $want_dir = shift ;
if($^O=~/win32/i){
system("start explorer $$want_dir");
}
}
EOF
endif