1

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.

3
  • 1
    on OSX :%w !pbcopy Commented Aug 9, 2015 at 10:03
  • I got /bin/bash: pbcopy: command not found Commented Aug 9, 2015 at 18:10
  • However +1 as it led me to an answer (below). Thanks! Commented Aug 9, 2015 at 18:32

3 Answers 3

4

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)

4
  • 3
    @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 Commented Aug 9, 2015 at 9:57
  • This simply didn't work for me. Commented Aug 9, 2015 at 18:13
  • 2
    @MichaelDurrant Hmm. OSX, isn't it? Try the + register (gg"+yG). Commented Aug 10, 2015 at 13:44
  • Thanks muru, Looks like my version of bash doesn't this functionality. I am on Yosemite 10.10.4 Commented Aug 10, 2015 at 17:59
1

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.

0

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.