Having a chunk of text selected in Vim's visual mode, I'd like to copy that to the system's clipboard (be it the primary or X11's). Is there an easy solution for this? Obviously, a simple y doesn't do the trick.
Asked
Active
Viewed 2,207 times
1
Oliver Salzburg
- 86,445
- 63
- 260
- 306
Boldewyn
- 4,328
- 5
- 38
- 52
2 Answers
3
you have to yank it to the clipboard register
"*y
:help registers will tell you more about that.
akira
- 61,009
- 17
- 135
- 165
-
1In my case, `"+y` copies to the "Ctrl-V" accessible clipboard. Thanks for the hint! – Boldewyn Mar 12 '10 at 11:22
-
well, keep the 2 buffers in sync with http://www.nongnu.org/autocutsel/ ... in the help of vim the diffs between the 2 clipboard mechanisms is explained as well. but since you are happy already ... :) – akira Mar 12 '10 at 11:33
2
The visual selection (v, V, or CTRL-V) can automatically be copied to the X11 selection (* buffer).
In non-gui mode the clipboard option controls this (only supported if +xterm_clipboard appears when you type vim --version). In gui mode guioptions controls it.
This makes all Visual mode selections automatically go to the X11 primary selection:
set clipboard+=autoselect
set guioptions+=a
This turns it off:
set clipboard-=autoselect
set guioptions-=a
See help 'clipboard' (single quotes required)