如何“复制到剪贴板"在Windows上的Bash中? [英] How to "copy to clipboard" in vim of Bash on Windows?

查看:82
本文介绍了如何“复制到剪贴板"在Windows上的Bash中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经使用"+y将文本复制到系统剪贴板中,但是在Windows上的Bash vim中不起作用.

I used to use "+y to copy text to system's clipboard, but it doesn't work in vim of Bash on Windows.

推荐答案

由于"* y"和"+ y(...)都不起作用,因此可以采用以下替代方法:

Since neither "*y nor "+y (...) work, an alternative is the following:

将此添加到您的.vimrc并创建一个名为~/.vimbuffer

Add this to your .vimrc and create a file called ~/.vimbuffer

" copy (write) highlighted text to .vimbuffer
vmap <C-c> y:new ~/.vimbuffer<CR>VGp:x<CR> \| :!cat ~/.vimbuffer \| clip.exe <CR><CR>
" paste from buffer
map <C-v> :r ~/.vimbuffer<CR>

使用视觉或视觉障碍物突出显示任何文本,然后按ctrl-c键. 使用通常的方法将复制的文本粘贴到终端外部,或者 在普通或可视模式下使用ctrl-v将复制的文本粘贴到任何vim窗格中.

Higlight any text using visual or visual-block and press ctrl-c. Paste copied text outside your terminal using the usual method or paste copied text to any vim pane using ctrl-v in normal or visual mode.

Ctrl-c提取选定的文本,用选定的文本覆盖~/.vimbuffer,运行UNIX命令以将数据从~/.vimbuffer传送到clip.exe.

Ctrl-c yanks the selected text, overwrites ~/.vimbuffer with the selected text, runs a UNIX command to pipe out the data from ~/.vimbuffer to clip.exe.

任何进一步的改进(例如:使命令保持静音)非常感激!

Any further improvement (e.g.: making command silent) is much appreciated!

命令现在可以复制任意长度的字符串,而不仅仅是整行. 旧命令:

command can now copy strings with any length, not just whole lines. Old command:

vmap <C-c> :w! ~/.vimbuffer \| !cat ~/.vimbuffer \| clip.exe <CR><CR>

这篇关于如何“复制到剪贴板"在Windows上的Bash中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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