English 中文(简体)
Copy text from Vim 7.2 running in xterm to windows clipboard
原标题:

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 ?

最佳回答

Try

"+3yy
"*3yy

"+p
"*p
问题回答

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!

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.





相关问题
Autoupdate VIM Plugins?

Is it possible to update vim plugins automatically?

how to unindent in vim without leaving edit mode?

I m writing a lot of python code recently, and i used the tab-to-space mode in vim. I was just wondering how would i unindent in vim without leaving edit mode for example after i finished if...: block....

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

Vim - Deleting XML Comments

How do I delete comments in XML? If the opening and the closing comment tags are on the same line, I use :g/^<!--.*-->$/d to delete the comment. How to delete the comments that are spread ...

Limiting a match in vim to certain filetypes?

I have the following in my .vimrc to highlight lines longer than 80 chars: highlight OverLength ctermbg=red ctermfg=white guibg=#592929 match OverLength /\%81v.*/ This works quite well. However, the ...

Profiling Vim startup time

I’ve got a lot of plugins enabled when using Vim – I have collected plugins over the years. I’m a bit fed up with how long Vim takes to start now, so I’d like to profile its startup and see which of ...

热门标签