Send echo or register contents to pbcopy / mac clipboard on mac os x

纵然是瞬间 提交于 2019-12-23 18:13:52

问题


I have a custom function in vimscript which creates a string and then echo's it to the bottom console. At the moment I copy and paste that output using cmd-c to copy it to the mac os x clipboard. I would like to shorten this workflow by just piping the echo to pbcopy, i tried:

:echo "hello" <BAR> !pbcopy

But of course that doesn't work. I also tried capturing the output into a register and then outputting it:

:@a!pbcopy

But it just trys to execute the string stored in @a, which is no a vim command. I feel like this should be straight forward, thanks.


回答1:


Assuming pbcopy takes its input from stdin you could try using system()

:call system('pbcopy', 'hello')
:call system('pbcopy', @a)

For more information see

:h system()



回答2:


What version of Vim do you use? In any reasonably up-to-date version (installed via Mac Ports/Homebrew or, better, MacVim) a simple

let @*="text"

will put text on the clipboard.

See :h clipboard.



来源:https://stackoverflow.com/questions/12414745/send-echo-or-register-contents-to-pbcopy-mac-clipboard-on-mac-os-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!