2

Has anyone found a good way to copy all lines from VIM in cygwin?
I've tried yanking the lines but it doesn't go to windows clipboard. Any ideas?

This seems to be a solution but it is a lot of work for copy/paste: http://vim.wikia.com/wiki/Using_the_Windows_clipboard_in_Cygwin_Vim

UPDATE: this works:

echo 'put this on my windows clipboard' > /dev/clipboard

BUT doesn't work for me because I want to copy to clipboard while SSH'd into another machine. So echo'ing/cat'ing to /dev/clipboard will put it on the other machine's clipboard, not mine

Mike Sallese
  • 827
  • 1
  • 10
  • 24

2 Answers2

4

There may be better ways, but here's how I do it:

Use visual mode to highlight lines to be copied to clipboard (From command mode, v, then navigate normally to highlight).

"+y

to copy to clipboard.

Since the question asks how to copy everything:

ggVG"+y
C.H.
  • 106
  • 4
  • I do like that. `ggVG"+y` copies everything :) – Camusensei Jun 17 '16 at 15:01
  • you don't really need to use visual mode to copy everything. `gg"+yG` is enough. – gniourf_gniourf Jun 17 '16 at 15:22
  • But then, in OP's link, it is clearly specified that `+` doesn't correspond to Windows' clipboard. So this answer will not work for Cygwin. – gniourf_gniourf Jun 17 '16 at 15:23
  • @gniourf_gniourf I just tried with my cygwin installed version of vim.exe, and gg"+yG successfully copied to windows clipboard – C.H. Jun 17 '16 at 15:30
  • @C.H. Good to know! then I wonder why vim's wiki states that `"+y`doesn't copy to Windows clipboard… or maybe something has changed recently… – gniourf_gniourf Jun 17 '16 at 16:00
  • @C.H. Isn't this solution the same thing as yanking but just yanking from visual mode? Which doesn't work for windows clipboard. I tried this and it doesn't work – Mike Sallese Jun 17 '16 at 16:06
  • @MikeSallese This is yanking to the + buffer, which is the windows clipboard. From what I've been reading you could also use * (but I haven't tested it) – C.H. Jun 17 '16 at 16:15
  • @C.H. the problem may be that I'm trying to do this while ssh'd into another machine. Because this doesn't work for me. I updated my question – Mike Sallese Jun 17 '16 at 16:28
  • 1
    @MikeSallese: Then try `ssh -X`. – gniourf_gniourf Jun 17 '16 at 16:33
  • @C.H. It gives me an error noise when I do "+. But when I highlight with my mouse and use y it works with the ssh -X – Mike Sallese Jun 17 '16 at 16:47
0

This is maybe not as easy as you wanted it to be, but here is how I usually do it myself:

:w
:!cat %

This will display your file, and you can copy it from there.

Camusensei
  • 1,475
  • 12
  • 20