与其他编辑器不同,vim将复制的文本存储在自己的剪贴板中。所以,对我来说,从网页复制一些文本并将其粘贴到当前的工作文件中是非常困难的。碰巧我必须打开gedit或手动输入它。

我可以使vim粘贴从和系统的剪贴板?


当前回答

还有一种方法是直接粘贴到'r'ead 'cat'输出:

:r!cat

这将在前台运行cat,所以你可以发送到终端你想要插入/在你的剪贴板。 完成后,发送ctrl+d以结束流。

这样做的好处是你不需要打乱缩进——文本就这样被插入。 注意,在cat位置可以有任何命令,比如fold(在发现gq之前我一直使用这个命令)或任何其他过滤工具。

虽然'+'寄存器似乎更vimic,但它并不适用于所有平台,而r!凯特只是在工作。

其他回答

如果你使用鼠标,首先做

 :set paste 

然后右击鼠标,缓冲区中的内容将被粘贴

进入vim窗口后,按“I”进入插入模式。然后将光标移动到需要的位置,同时按Ctrl + Insert按钮从剪贴板粘贴。

由于vim 8的右键单击默认启用可视模式。这可以防止“正常的”复制和粘贴(称之为“设计缺陷”https://github.com/vim/vim/issues/1326)。 解决方法:

回显“set mouse-=a”>> ~/。vimrc。

退出并重启vim。

When I use my Debian vim that is not integrated with Gnome (vim --version | grep clip # shows no clipboard support), I can copy to the clipboard after holding the Shift key and selecting the text with the mouse, just like with any other curses program. As I figured from a comment by @Conner, it's the terminal (gnome-terminal in my case) that turns off its mouse event reporting when it senses my Shift press. I guess curses-based programs can receive mouse events after sending a certain Escape sequence to the terminal.

对于一些国际键盘,您可能需要按“+空格获得a”。

所以在这种情况下,你必须按“空格+y”或“空格*y”来复制。

空格+p或者空格*p来粘贴。