5

I'm using Vim 7.2 , compiled with +xterm_clipboard , in a xterm through putty . I've put set clipboard=unnamed in .vimrc , and from what i've read in other threads , this should put all yanks/deletes to the system clipboard. However , when I'm trying to paste whatever i've yanked to a MS app like notepad, its not working.

When I select text in vim using mouse , it automatically gets copied to the system(MS clipboard). I'd like to have the same functionality while using keyboard commands like 3yy .

Can anyone tell me what I'm doing wrong ?

TCSGrad
  • 11,898
  • 14
  • 49
  • 70
  • "in an xterm through putty" is ambiguous. Either you ssh to a Linux box with putty, with no xterm involved. Or you're running an X server on Windows, and forwarding it with putty's X11 ssh forwarding. Then you run an xterm over that. In this case, it doesn't matter that it's putty doing the X11 forwarding. – Peter Cordes Aug 29 '15 at 00:42
  • Also, this belongs on superuser.com – Peter Cordes Aug 29 '15 at 01:01

3 Answers3

2

Try

"+3yy
"*3yy

"+p
"*p
Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173
  • Can you tell me how to do a `"+p` in notepad ? :) What you told me would work if I open another vim session and paste it there - I know that . What I wanted was a way to copy it into the Windows clipboard , which I can then paste it into notepad ! If you think I was a bit unclear, I'm being even more explicit : I'm running Win XP on my PC , and using putty to get an xterm on the remote machine , where the file is opened in vim ! – TCSGrad Dec 09 '09 at 10:29
  • In the notepad you do paste. I'm not sure exactly how it works on windows, but on unices it yanks stuff into "system" selection. I'd guess that one of those will do that on windows as well. It also depends on the Xserver implementation on the windows and how it handles selection. I can only give you a vim-related part of the answer. – Michael Krelin - hacker Dec 09 '09 at 11:08
  • 1
    Thats what I wanted to convey : yanking text to system buffer does not put it in the windows clipboard , and hence I can't paste it anywhere. I guess the answer , if it exists , would involve setting some putty/X configurations to ensure vim has a way of putting text in the windows clipboard. – TCSGrad Dec 09 '09 at 14:06
  • I'm not quite sure I understand what your setup it. You mention both putty and xterm. Does it mean that you run local X-server, connect to the machine using putty and then using putty's tunnel open xterm on your local X-server? If so, then you should look into your X-server settings. I haven't seen windows X-server for about 10 years now... ;-) – Michael Krelin - hacker Dec 09 '09 at 20:17
  • OK - so here's my setup : 1) Native OS is win XP 2) I have a account in a linux box which I connect to using Putty 3) The value of the $TERM env variable is TERM=xterm 4) The shell I primarily use in my linux accout is tcsh 5) I use vim 7.2 I appreciate your efforts to answer my question - and thats why I'm trying to be as precise as possible in my description !! – TCSGrad Dec 10 '09 at 03:04
  • 1
    Ah, so you *don't* use xterm, you use putty and hope it will behave like xterm. Which may be possible, but it's beyond my expertise. I'd look for putty options. Not sure if there are any of interest... – Michael Krelin - hacker Dec 10 '09 at 08:07
1

If you were running vim locally, then either

"+p
"*p

would work, as mentioned by hacker. Since you're sshed into another box, these will just copy text to the clipboard of the box you're sshed into.

What you need is the putty method of copying text, which is just highlighting the text you want to copy with the mouse.

While sshed into vim though, I usually use ALT + highlight with the mouse (for block selection), as I usually have line numbers on.

Hope this helps!

Nick Knowlson
  • 7,185
  • 6
  • 47
  • 63
  • Yes , I know using mouse works - thats mentioned in the question. But the point of using vim is that you don't have to depend on the mouse - there's always an alternative (usually). However, in this case , I think I'm asking a bit too much of vim , so I guess i'll have to look for ways of sharing clipboards across ssh !! – TCSGrad Dec 11 '09 at 18:09
  • Oh right, I missed that bit, sorry! If your vim is compiled with the X11 and xterm_clipboard features enabled, and you turn on X11 forwarding in PuTTY, then this might work. – Nick Knowlson Dec 11 '09 at 19:04
  • As far as I remember , I had enabled X11 forwarding in putty ... but it was still not working - I'll check and verify – TCSGrad Dec 12 '09 at 01:32
  • X11 forwarding means you can run a graphical application on the Linux box and have the GUI appear on the windows box you're connecting from. You might want to try running xvim/gvim. – Adam Luchjenbroers Dec 13 '09 at 00:56
0

I'm trying to figure out how to get vim inside PuTTY (no xterm involved) to interact with the Windows clipboard.

My research so far indicates it's not possible. xterm has clipboard-interaction terminal escape sequences, but they're disabled by default in xterm. They're probably not implemented at all in PuTTY. This is probably for security reasons: you don't want a remote system to have full access to your clipboard.

I'm not sure if that's what vim's xterm_clipboard feature is supposed to use, anyway. My searching so far only turns up people complaining about it not being enabled, or talking about how to get a vim that has it enabled, not how it's actually implemented. The best I've found is this guide which mentions it, but doesn't say anything that would pin it down to escape sequences vs. X selection vs. X clipboard. (Yes, X11 has a selection and a separate clipboard. Some ways of copying only set one or the other.)


Vim's clipboard support talks directly to the X server. On a Linux desktop, with vim in a terminal (Konsole in my case) :"*dd does put the lines into the clipboard.

With

(unset DISPLAY; strace -s256 -o /dev/pts/18 vim some_file.txt)

vim doesn't have an X server to talk to. (pts18 is the tty of another terminal window.) I thought vim might use xterm escape sequences to set the clipboard, but it doesn't. There is no write(1, ...) system call with the whole region, so it's clearly not trying to use an escape sequence to put the region in the clipboard via xterm.

I ran this inside a Konsole with TERM=xterm, on Ubuntu 15.04. I also tried inside a real xterm.

Oh, xterm disables GetSelection/SetSelection by default. Maybe with this enabled, vim would try to use it? IDK if this helps, though, because PuTTY would also have to support it, which is unlikely.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847