Yank entire file
VimClipboardViVim Problem Overview
I often write something in gVim, then need to copy-paste it into another application.
Is there an easy way to yank the entire file? I usually do something like this
ggVG"+y
(Go to top, visual-line mode, go to bottom, yank)
But is there a better way that I'm missing out on?
Vim Solutions
Solution 1 - Vim
I use the following instruction: :%y+
Solution 2 - Vim
ggyG
(go to the first line, yank to the last line)
Edit: Ah, system clipboard. Doesn't exactly roll off the fingers, but: gg"+yG
Solution 3 - Vim
A working solution in old vi is :r filename
in the new file.
Solution 4 - Vim
Another method is this:
ggyG
Go to the top, and yank to the bottom.
Solution 5 - Vim
I use the following instruction: :%y
.
Solution 6 - Vim
ggyG
(Go to top, yank to bottom)
Solution 7 - Vim
:0,$ y
I dunno which way is easier.
Solution 8 - Vim
Or simply in your .vimrc
:
nmap <silent> <F5> ggVG"+y
So you can just use one key :)
Solution 9 - Vim
In OSX:
ggVG
!tee >(pbcopy)
Which I find nicer than:
ggVG
:w !pbcopy
Since it doesn't flash up a prompt: "Press ENTER or type command to continue
"
Solution 10 - Vim
:%y
without +
works over the entire system if you are using neo-vim (nvim).
This lets us avoid stretching our fingers to the +
- acctually making this shortcut better than ggyG
.
Solution 11 - Vim
Depending on how often you do it, just map a key for this and optionally add to the vimrc
:nnoremap <F5> :%y
or
:nnoremap <leader><whatever> :%y
or whatever key you know is safe and is fastest—then add to a mappings source or whatever. The advantage to this over ggyG
is that it's not moving the cursor (faster) and to retain your cursor position you'd have to add a <Ctrl-o><Ctrl-o>
People often forget that commands are session based unless in the vimrc. I often know when I'm going to do a lot of something but don't need it as default and just :[mode]remap <whatever> <whatever>
I can close and re-open vim if I need to.
If <Ctrl-A><Ctrl-C>
works for you then you’re using mswin.vim in your source and losing out on the power of increment <Ctrl-a>
and decrement <Ctrl-x>
operations (among other things). I started in windows and stopped using mswin.vim along time ago. I personally feel it's best to grok Vim the right way and then add in the crutches you really need :P
Solution 12 - Vim
It's dirty but you don't have to use the shift key at all and only 3 different keys which may be faster:
gg1111yy
(Assuming the file is shorter than 1111 lines)
Solution 13 - Vim
On Windows I often just do CTRL-A, CTRL-C to copy all to the windows clipboard... Can't get easier than that!
I'm using a standard gvim 7.1 from the website...
(BTW: also works on my mac with MacVim and that funny mac-key+A, mac-key+C)