Vim is acting as if you had typed all of your pasted code by hand, so Vim will add additional indentation and otherwise change whitespace as it normally would, such as with your `autoindent` setting. To paste code in Vim:
1. `:set paste` to enable paste mode.
2. Paste your code.
3. `:set nopaste` to disable paste mode so your normal typing will work as expected again.
And see `:help paste` for more information, including which options are disabled/altered when paste mode is on.
It's possible to set up mappings for this sort of thing if you do it a lot. See `:help imap` for more information on that.