问题
I have a bash script which takes a single argument and returns around 8-10 lines of text.
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.
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.
Any advice would be much appreciated.
after a bit of googling I've come up with
function! Foo(a1)
new
r !myscript a:a1
endfunction
This doesn't quite work yet. It seems to pass the name a:a1 rather than the value.
回答1:
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>
This will call the script with the currently selected text when you hit QQ
来源:https://stackoverflow.com/questions/6974440/vim-function-to-call-bash-script-with-argument-and-return-result