Vim:将所选文本管道到shell cmd并在vim info /命令行上接收输出 [英] Vim: Pipe selected text to shell cmd and receive output on vim info/command line

查看:176
本文介绍了Vim:将所选文本管道到shell cmd并在vim info /命令行上接收输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所选文本传递给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), "\n")).'| 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 info /命令行上接收输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆