Vim:将选定的文本通过管道传送到 shell cmd 并在 vim 信息/命令行上接收输出 [英] Vim: Pipe selected text to shell cmd and receive output on vim info/command line
问题描述
我想将选定的文本通过管道传送到一个 shell 命令并在 vim info/命令行上接收这个 shell 命令的单行输出?
I want to pipe the selected text to a shell command and receive the one-line output from this shell command on the vim info/command line?
我真正想做的是:将选定的文本通过管道传送到 pastebin 类型的 shell 命令,我想接收 shell cmd 的输出(这是到 pastebin 的 http 链接).这可能吗?
What I'm really trying to do: Pipe the selected text to a pastebin-type shell command and I want to receive the output of the shell cmd (which is the http link to the pastebin). Is this possible?
推荐答案
我会这样做:
把这个函数放在你的 vimrc 中:
Place this function in your vimrc:
function Test() range
echo system('echo '.shellescape(join(getline(a:firstline, a:lastline), "
")).'| pbcopy')
endfunction
这将允许您通过执行以下操作来调用此函数:
This will allow you to call this function by doing:
:'<,'>call Test()
然后你也可以这样映射(就在你的 vimrc 中的函数声明下):
Then you can also map that like this (just under the function declaration in your vimrc):
com -range=% -nargs=0 Test :<line1>,<line2>call Test()
所以你可以调用这个函数:
So you can call the function doing this:
:'<,'>Test
注意: :<','>
是范围选择器,为了产生它们,只需在可视模式下选择相关行,然后进入命令模式(按冒号键)
Note: :<','>
are range selectors, in order to produce them just select the pertinent lines in visual mode and then go to command mode (pressing the colon key)
这篇关于Vim:将选定的文本通过管道传送到 shell cmd 并在 vim 信息/命令行上接收输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!