Vim函数使用参数调用bash脚本并返回结果 [英] Vim function to call bash script with argument and return result
问题描述
我有一个bash脚本,它带有一个参数,并返回大约8-10行文本.
I have a bash script which takes a single argument and returns around 8-10 lines of text.
我希望能够在vim中调用此脚本.理想情况下,突出显示字符串作为参数.然后,我希望脚本的输出显示在新窗格中.
I'd like to be able to call this script from within vim. Ideally by highlighting a string of characters as the argument. I'd then like the output of the script to be displayed in a new pane.
我是vim的新手,所以不确定是否可以仅通过在vimrc文件中创建命令来完成此操作,或者我是否需要创建插件.
I'm new to vim so I'm not sure if this can be done simply by creating a command in my vimrc file or if I need to create a plugin.
任何建议将不胜感激.
经过一番谷歌搜索后,我想到了
after a bit of googling I've come up with
function! Foo(a1)
new
r !myscript a:a1
endfunction
这还行不通.似乎传递的名称是a:a1而不是值.
This doesn't quite work yet. It seems to pass the name a:a1 rather than the value.
推荐答案
我将从这样一个简单的函数开始(注意:该示例使用echo
作为脚本... Kinda me脚...但你明白了)
I'd start with a simple function like so (note: the sample uses echo
as the script... Kinda lame... but you get the idea)
function! CallMyScript(params)
new " open a new buffer
" se buftype=nofile " add spice to taste, e.g.
silent! exec "r!echo '" . a:params . "'"
endfunction
,然后是可视模式的映射,例如;
and then a mapping for visual mode like;
:vnoremap QQ y:call CallMyScript(@")<Enter>
当您按下 Q Q
这篇关于Vim函数使用参数调用bash脚本并返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!