2014-01-16 218 views
0

我目前正在编写一个Makefile,其任务是将给定文件中的文本内容复制到计算机的实际剪贴板中。将文本复制到剪贴板

我认为的一种方式是使用特殊的启动命令(选项-c'命令')运行vim。所以我想用

vim -c '%w !pbcopy | q' 

这不起作用,因为!pbcopy提示回车(我认为)。无论如何,在运行时Vim告诉我

zsh:1: command not found: q 

shell returned 127 

Press ENTER or type command to continue 

糟透了。

任何其他方式,我可以做到这一点?在这个double vim命令中绕过回车问题,或者简单地找到另一种方法从我的终端(我使用Zsh)复制我的文本。

在此先感谢!

+0

好吧,这是有道理的现在:pbcopy是一个命令行呢(这我现在正在发现),所以在爆炸之后(!)我们就是炮弹。这就是为什么它抱怨的原因。 现在,如何正确使用pbcopy? – Charles

+3

虽然'猫your_filename | pbcopy'会这么做...... – John3136

+1

@ John3136'pbcopy FDinoff

回答

2

你根本就不需要Vim;你在做什么等同于在世界各地旅行,只是为了从前廊取阅报纸。

解释Vim错误:有一些Vim命令可以链接在一起,例如, :version | help,但某些命令可以采用任意参数(包括|命令分隔符),因此链接不是直接可能的。正如你可以在:help :|看到的那样,:write !命令就是其中之一。您可以解决此通过环绕:execute命令(支持链接):

:execute '%w !pbcopy' | q 
+0

哈,很好。尽管我的问题很愚蠢,但你把它变成了一些有趣和信息丰富的东西。那谢谢啦 ! – Charles

2

引述pbcopy(1)

pbcopy takes the standard input and places it in the specified pasteboard. If no pasteboard is specified, the general pasteboard will be used by default. The input is placed in the paste- board as plain text data unless it begins with the Encapsulated PostScript (EPS) file header or the Rich Text Format (RTF) file header, in which case it is placed in the pasteboard as one of those data types.

所以,你只需要做命令pbcopy < file

熟悉Unix命令man它给你访问的命令手册页。当你熟悉它时,很容易为自己得到这些问题的答案。

+0

有趣的是,我绝对不是Unix或Vi的新手。我新来的,是愚蠢的。 – Charles

0

您可以使用XCLIP:

cat file | xclip -i -selection clipboard