Is there any way to copy all lines from open file to clipboard in VI editor. I tried yG but it\'s not using clipboard to store those lines.
So
:set go=a
ggVG
See :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.
The clipboard is buffer +. To copy to clipboard, do "+y and [movement].
So, gg"+yG will copy the whole file.
Similarly, to paste from clipboard, "+p
You can use a shortcur, like this one:
noremap <F6> :%y+<CR>
It means, when you push F6 in normald mode, it will copy the whole file, and add it to the clipboard.
Or you just can type in normal mode :%y+
and then push Enter
.
Use:
:%y+
to yank all lines.
Explanation:
%
to refer the next command to work on all the linesy
to yank those lines+
to copy to the system clipboardNB: In Windows, +
and *
are equivalent see this answer.
Here's a map command to select all to the clipboard using CTRL+a:
"
" select all with control-a
"
nnoremap <C-a> ggmqvG"+y'q
Add it to your .vimrc and you're good to go...
On Ubuntu 12
you might try to install the vim-gnome
package:
sudo apt-get install vim-gnome
I tried it, because vim --version
told me that it would have the flag xterm_clipboard disabled (indicated by - ), which is needed in order to use the clipboard functionality.
-> installing the vim-gnome package on Ubuntu 12 also installed a console based version of vim, that has this option enabled (indicated by a + before the xterm_clipboard flag)
On Arch Linux
you may install vim-clipboard
for the same reason.
If you run neovim then you should install xclip
(as explained by help clipboard-tool
)