How to copy contents of a (large) vim file to the OSX system clipboard to paste in other apps?
Solution 1
I've solved this in a better way than my other answer:
First of all get the new vim with
brew install vim
and then do
vim --version
Make sure it is 7.4+ Note that if you do vi --version you may that vi is at 7.3
Now make vi use that newer vim
alias vi=vim
and add that alias to your .bash_aliases file (or wherever you put aliases)
Finally add
set clipboard=unnamed
to your .vimrc
(not .bashrc
!)
Start a new shell and it should work.
Solution 2
I'm sure this is a duplicate but:
gg"*yG
gg
go to the first line
"*y
start a yank to the system clipboard "register"
G
move to the end of the file (you will see how many lines were yanked)
Solution 3
This alternative option using a :
command worked for me:
:1,$!pbcopy
This is useful for referring to line numbers, etc without having to navigate and highlight the area.
Related videos on Youtube
Comments
-
Michael Durrant over 1 year
I like to use vim to edit other (non-programming languages) stuff. So I paste the content into vim and make the changes.
How can I copy all of the text back into the primary clipboard for pasting?
Note that I use iTerm2 and the ability to use * isn't there as it is with the basic osx terminal app.
I don't want to copy to a vim internal register (such as the
y
yank command), I want to copy to the system clipboard.Also, I want the contents of the whole file, including the content which is off-screen?
The alt-left-click-drag with mouse doesn't work.
-
Evgeny Vereshchagin over 8 yearson OSX
:%w !pbcopy
-
Michael Durrant over 8 yearsI got
/bin/bash: pbcopy: command not found
-
Michael Durrant over 8 yearsHowever +1 as it led me to an answer (below). Thanks!
-
-
muru over 8 years@MichaelDurrant talking in ALL CAPS doesn't make you right. The
*
and+
buffers are for interfacing with the system clipboard. See vi.stackexchange.com/a/96/205 -
Michael Durrant over 8 yearsThis simply didn't work for me.
-
muru over 8 years@MichaelDurrant Hmm. OSX, isn't it? Try the
+
register (gg"+yG
). -
Michael Durrant over 8 yearsThanks muru, Looks like my version of bash doesn't this functionality. I am on Yosemite 10.10.4