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

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

问题描述

我曾经使用 "+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 命令将数据从 ~/.vimbufferclip.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 :w!~/.vimbuffer |!cat ~/.vimbuffer |clip.exe

Edit2:下面的@Tropilio 在使用系统事件的评论中有更简洁的方法.我已经用了一年了.

Edit2: @Tropilio below has a much cleaner approach down in the comments using system events. I've been using that for a year now.

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

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