是否可以直接从Vim复制到剪贴板?yy只把东西复制到Vim的内部缓冲区。我想复制到操作系统的剪贴板。在Vim中有这样的命令吗?或者你只能在Vim中提取东西?
当前回答
我的解决方案是把下面的行放在。vimrc:
map <C-y> :w !xclip -sel c <CR><CR>
脚本使用Ctrl + y将所选的行(通过可视模式)或文件内容(如果没有被选择)复制到剪贴板。如果这很重要,我使用的是Manjaro Linux。
其他回答
我不能复制到剪贴板的系统中,因为我的~/中有这个。vimrc文件:
if has('mouse')
set mouse=a
endif
但如果你接下来添加这一行,它将允许你简单地按Ctrl+c将你所选择的任何东西放入剪贴板。
vmap <C-c> "+y
原始讨论和更多详细信息:启用set mouse=a从vim中复制文本
In case you don't want to use any graphical interface for vim and you prefer to just stick with terminal emulator there may be a much simpler approach to this problem. Instead of using yank or anything like this, first take a look at documentation of terminal you use. I've been struggling with the same issue (trying to use +clipboard and xclip and so on) and in the end it turned out that in my terminal emulator it's enough to just press shift and select any text you want to copy. That's it. Quite simple and no need for messing with configuration. (I use urxvt by the way).
如果你正在使用GVim,你也可以设置guioptions+=a。这将触发自动复制到剪贴板的文本,您在视觉模式突出显示。 缺点:注意,高级剪贴板管理器(历史)将在这种情况下得到你所有的选择历史…
在Mac OSX上
复制所选部分:可视选择文本(正常输入v或v) 模式)和类型:w !pbcopy 复制整个文件:%w !pbcopy 从剪贴板粘贴:r !pbpaste
在大多数Linux发行版上,你可以替换:
用xclip -i -sel c或xsel -i -b拷贝上面的内容 使用xclip -o -sel -c或xsel -o -b进行Pbpaste 注意:如果这些工具(xsel和xclip)都没有预先安装在你的发行版上,你可以在回购中找到它们
在我的情况下,使用鼠标和右键复制的帮助进行选择。
我不希望包括行号,所以我:在复制之前设置nonnumber。