In Vim, if I paste this script:#!/bin/shVAR=1while ((VAR <  10))    do        echo VAR1 is now $VAR        ((VAR = VAR +2))    done    echo finishI get these strange results:#!/bin/sh#VAR=1#while ((VAR <  10))#       do#                       echo VAR1 is now $VAR#                                       ((VAR = VAR +2))#                                               done#                                                       echo finish#                                                       Hash signs (#) and tabs have appeared. Why?
Why does Vim indent pasted code incorrectly?
vim;clipboard;whitespace
There're two reasons:Auto insert commentAuto indentingFor pasting in vim while auto-indent is enabled, you must change to paste mode by typing::set pasteThen you can change to insert mode and paste your code. After pasting is done, type::set nopasteto turn off paste mode. Since this is a common and frequent action, vim offers toggling paste mode:set pastetoggle=<F2>You can change F2 to whatever key you want, and now you can turn pasting on and off easily.To turn off auto-insert of comments, you can add these lines to your vimrc:augroup auto_comment    au!    au FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=oaugroup ENDvim also provides a pasting register for you to paste text from the system clipboard. You can use *p or +p depending on your system. On a system without X11, such as OSX or Windows, you have to use the * register. On an X11 system, like Linux, you can use both.Further readingAccessing the system clipboardHow can I paste something to the VIM from the clipboardfakeclip