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

那么这可能吗?


当前回答

剪贴板为buffer +。要复制到剪贴板,请执行“+y和[移动]”。

gg"+yG会复制整个文件。

类似地,要从剪贴板粘贴,“+p

其他回答

下面是一个映射命令,使用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>。

我已经创建了一个函数来执行这个操作,把它放在~/.vimrc上。

fun! CopyBufferToClipboard()
    %y+
endfun
nnoremap <Leader>y :call CopyBufferToClipboard()<CR>
command! -nargs=0 CopyFile :call CopyBufferToClipboard()

OBS:如果你正在使用neovim,你还需要一些剪贴板管理器,比如xclip。有关更多信息,请在neovim中键入:h checkhealth

同样重要的是要提到的是,并不总是简单的y会复制到剪贴板,为了使每次复制feed + wich是“剪贴板寄存器”尝试set::set clipboard=无名,无名加。更多信息见::h未命名。

这里有更多关于vim wikia的信息。

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

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

:%!xclip -sel clip
u

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

sudo apt-get install xclip

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.