是否有任何方法复制所有行从打开的文件到VI编辑器剪贴板。我试过yG,但它没有使用剪贴板来存储这些行。

那么这可能吗?


当前回答

(回复@rshdev,并避免在OP的注释中使用@nelstrom +xterm_clipboard重新编译vim)

在Ubuntu 11上有一个叫xclip的程序,它的工作原理类似于putclip:

:%!xclip -sel clip
u

默认情况下不会安装。安装方法:

sudo apt-get install xclip

其他回答

Ubuntu 12

你可以尝试安装vim-gnome包:

sudo apt-get install vim-gnome

我尝试了一下,因为vim——version告诉我它将禁用xterm_clipboard标志(由-指示),这是使用剪贴板功能所必需的。

在Ubuntu 12上安装vim-gnome包的>也安装了一个基于控制台的vim版本,该版本启用了这个选项(xterm_clipboard标志前的+表示)

在Arch Linux上

出于同样的原因,您可以安装vim-clipboard。

如果运行neovim,则应该安装xclip(参见help clipboard-tool)

gVim:

:set go=a

ggVG

看:help go-a:

'a' Autoselect:  If present, then whenever VISUAL mode is started,
 or the Visual area extended, Vim tries to become the owner of
 the windowing system's global selection.  This means that the
 Visually highlighted text is available for pasting into other
 applications as well as into Vim itself.  When the Visual mode
 ends, possibly due to an operation on the text, or when an
 application wants to paste the selection, the highlighted text
 is automatically yanked into the "* selection register.
 Thus the selection is still available for pasting into other
 applications after the VISUAL mode has ended.
     If not present, then Vim won't become the owner of the
 windowing system's global selection unless explicitly told to
 by a yank or delete operation for the "* register.
 The same applies to the modeless selection.

下面是一个映射命令,使用CTRL+a选择所有到剪贴板:

"
" select all with control-a
"
nnoremap <C-a> ggmqvG"+y'q

将它添加到你的.vimrc,你就可以开始了…

:%y a把所有的内容放到vim的缓冲区中, 在命令模式下按下p键将会在你的光标当前所在的行之后粘贴被拖拽的内容。

如果你在使用VI时遇到问题,另一种简单的复制整个文件的方法就是输入“cat filename”。它会将文件回显到屏幕上,然后你可以上下滚动并复制/粘贴。