I suggest using the CLI utility to put it on the clipboard: there are several that I found earlier, but here is one:
So you would do
:%!sed 's:^:\t:g`|xclip
or
:%!sed 's:^:\t:g`|xclip -selection c
the latter uses the X clipboard instead of the main clipboard (assuming UNIX).
The windows have similar similar utilities.
Edit
A clean vim solution would be:
:let @+=substitute(join(getbufline("%", 1, "$"), "\r\n"), "^\\|\n", "\&\t", "g")
Notes:
- it's not very efficient (but you use its SO messaging ... so it's not Homer Oddyssee)
- I assume that you want windows strings to end (which is what I get when copying from SO anyway).
source share