是否有任何方法复制所有行从打开的文件到VI编辑器剪贴板。我试过yG,但它没有使用剪贴板来存储这些行。
那么这可能吗?
是否有任何方法复制所有行从打开的文件到VI编辑器剪贴板。我试过yG,但它没有使用剪贴板来存储这些行。
那么这可能吗?
当前回答
在Bill Joy的vi中没有“剪贴板”的概念,所以我不认为有内置的方法来做到这一点。
gVim的自动复制任何高亮显示到剪贴板的功能是最简单的或使用外部程序通过:!
对于Cygwin的vim,我使用
:%!putclip
u
也许Ubuntu有一个CLI应用程序,比如putclip??
其他回答
我已经创建了一个函数来执行这个操作,把它放在~/.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的信息。
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.
虽然上面的许多答案都很出色,但没有一个解决方案适合我,因为我使用的是Ubuntu 16.04附带的默认VIM安装,并且默认没有安装剪贴板选项。我还想把文本粘贴到一个外部程序中。
解决方案:Ubuntu的默认终端允许你通过点击编辑然后全选来高亮显示全部内容。
你可以按下gg将光标定位到文件的开头,然后按yG将所有内容从开始到结束(G定位)复制到缓冲区。好运!