If your vim have auto indent enabled, you may facing this problem. Vim are too smart to help you indent copied source code, and the comment line will kill your pasting very much. I usually do copy and paste source code from ebook or web page to a file so that I can compile and run for test. In this case vim is not helping. I use cat instead.
Let say I copy a sample source code from the web, by typing the command line bellow:
cat > sample.c
I can now paste the source code and press Enter to insert a new line then ctrl+d after finish pasting.
Okay its done, now I can compile the sample source code.