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

那么这可能吗?


当前回答

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

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

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

其他回答

这是我所做的拉出整个文件:

ggVGy

在Bill Joy的vi中没有“剪贴板”的概念,所以我不认为有内置的方法来做到这一点。

gVim的自动复制任何高亮显示到剪贴板的功能是最简单的或使用外部程序通过:!

对于Cygwin的vim,我使用

:%!putclip
u

也许Ubuntu有一个CLI应用程序,比如putclip??

我尝试了上面人们提到的一些命令。没有工作。 然后我找到了其中最简单的一个。

步骤1:vi <filename> 第二步:右键单击Putty窗口的标题栏 步骤3:选择“清除屏幕”(以避免复制SSH会话的其余部分) 第四步:再次右键单击并选择“复制所有到剪贴板”。

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.

我在我的.vimrc中添加了以下一行

nnoremap <F5> :%y+<CR>

这允许我通过按F5(在命令模式下)将Vim中的所有文本复制到剪贴板。