tags:

views:

145

answers:

3

Is it possible to copy to clipboard directly from vim? e.g I want to be able to use all the functionality that a normal vim command allows, like lets say if cc means copy line to clipboard, then 4cc should copy 4 lines etc. Is there any such command in vim or you can only yank stuff within vim?

+3  A: 

Use the register "+ to copy to the system clipboard (i.e. "+y instead of y).

Likewise you can paste from "+ to get text from the system clipboard (i.e. "+p instead of p).

Amardeep
I use "*, but it seems that there's only a difference in X.
dash-tom-bang
@dash-tom-bang: the `+`/`*` difference is `SELECTION` vs `PRIMARY` copy buffers (can't recall which is which atm)
Daenyth
Yeah star is the selection, plus is the clipboard.
dash-tom-bang
+7  A: 

The * register will do this. In Windows, + and * are equivalent. In unix there is a subtle difference between + and *:

Under Windows, the * and + registers are equivalent. For X11 systems, though, they differ. For X11 systems, * is the selection, and + is the cut buffer (like clipboard). http://vim.wikia.com/wiki/Accessing_the_system_clipboard

* is probably what you want most of the time, so I use * because it functions as I expect it to in both environments.

Gabe Moothart
+5  A: 

If you are using GVim, you can also set guioptions+=a. This will trigger automatic copy to clipboard of text that you highlight in visual mode.
Drawback: Note that advanced clipboard managers (with history) will in this case get all your selection history…

Benoit