是否可以直接从Vim复制到剪贴板?yy只把东西复制到Vim的内部缓冲区。我想复制到操作系统的剪贴板。在Vim中有这样的命令吗?或者你只能在Vim中提取东西?
当前回答
如果你的vim编译时没有+xterm_clipboard选项,就像Debian和Ubuntu中默认的那样,你可以将选择或整个缓冲区输送到处理桌面剪贴板的外部程序。对于xclip(您可能需要在前面安装它),命令将是:w !xclip -sel clip
其他回答
Shift + Ctrl + C 如果你在Linux的图形模式,但首先你需要选择你需要复制什么。
我的解决方案是把下面的行放在。vimrc:
map <C-y> :w !xclip -sel c <CR><CR>
脚本使用Ctrl + y将所选的行(通过可视模式)或文件内容(如果没有被选择)复制到剪贴板。如果这很重要,我使用的是Manjaro Linux。
对于一些国际键盘,您可能需要按“+空格获得a”。
所以在这种情况下,你必须按“空格+y”或“空格*y”
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).
除了vim-gnome, Ubuntu 20.04的neovim默认也支持+y。
如果你不想安装一个新程序,你可以使用cat file.txt或gedit file.txt的惰性方法从那里复制。