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

那么这可能吗?


当前回答

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

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

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

其他回答

如果您的手指默认使用CTRL-A CTRL-C,那么尝试从$VIMRUNTIME/mswin.vim映射。

" CTRL-C and CTRL-Insert are Copy
vnoremap <C-C> "+y

" CTRL-A is Select all
noremap <C-A> gggH<C-O>G
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
onoremap <C-A> <C-C>gggH<C-O>G
snoremap <C-A> <C-C>gggH<C-O>G
xnoremap <C-A> <C-C>ggVG

我将它们映射到<Leader><C-a>和<Leader><C-c>。

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.

虽然上面的许多答案都很出色,但没有一个解决方案适合我,因为我使用的是Ubuntu 16.04附带的默认VIM安装,并且默认没有安装剪贴板选项。我还想把文本粘贴到一个外部程序中。

解决方案:Ubuntu的默认终端允许你通过点击编辑然后全选来高亮显示全部内容。

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

ggVGy

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