是否可以直接从Vim复制到剪贴板?yy只把东西复制到Vim的内部缓冲区。我想复制到操作系统的剪贴板。在Vim中有这样的命令吗?或者你只能在Vim中提取东西?
当前回答
除了vim-gnome, Ubuntu 20.04的neovim默认也支持+y。
如果你不想安装一个新程序,你可以使用cat file.txt或gedit file.txt的惰性方法从那里复制。
其他回答
使用寄存器“+”复制到系统剪贴板(即。+y而不是y)。
同样,您可以从“+”粘贴从系统剪贴板(即。"+p而不是p)。
@Jacob Dalton has mentioned this in a comment, but nobody seems to have mentioned in an answer that vim has to be compiled with clipboard support for any of the suggestions mentioned here to work. Mine wasn't configured that way on Mac OS X by default and I had to rebuild vim. Use this the command to find out whether you have it or not vim --version | grep 'clipboard'. +clipboard means you're good and the suggestions here will work for you, while -clipboard means you have to recompile and rebuild vim.
这个问题已经有很多答案了。我在添加我的方法,我觉得很快。
快速地,你可以按V (Shift + V)到激活可视模式。在可见模式下,可以使用j和k选择要复制的文本。选择后使用
"*y
现在,选定的文本被复制到剪贴板。
到目前为止,我在MacOsX上使用键盘快捷键已经为此挣扎了几个月。 我知道问题不是关于使用键盘短裤。但这可能会对有同样担忧的人有所帮助。
我发现如果你不勾选:
View ->允许鼠标报告
从终端菜单,您将能够复制到剪贴板使用
Command + c
一次。
我想补充一种方法来复制一行到剪贴板,并在函数上使用它。
这里有一个你在浏览器中打开URL的例子
let g:chrome_exe = 'C:/.../Google/Chrome/Application/chrome.exe'
function OpenURL()
" copy the line and put it in the register *
normal "*yy
:execute "silent !start ".g:chrome_exe." ".getreg("*")
endfunction
map ,url :call OpenURL()<CR>