In a clean installation of VS Code (1.59.1) the code pasted in the integrated terminal has a different indentation than the one available in the editor. I tried changing the parameter "editor.formatOnPaste": true and there was no improvement. This problem does not exist when I copy the same content and paste it into the powershell or command prompt. Any ideas on how to solve this?
I just tried to reproduce your problem on Linux (bash, tmux, zsh, etc.) and Windows (PowerShell, Command Prompt, etc.) without much success.
I am willing to bet it is a problem with the 'ipython' you are running in PS.
Have you tried installing a different Python version just to see if that is the issue?
I think you have to import and initialize ipython or you have given an extra space.
I couldn't reproduce your problem myself, but here are some solutions I think they might work.
I believe the source of this problem may have something to do with Ipython's automatic indentation when working with the vscode version you are using. You could use Ipython's built-in magic command: %autoindent to turn off the automatic indentation.
Just run the magic command: %autoindent and you will see in your prompt the message:
Automatic indentation is: OFF (You can run it again to turn it back on if you want)
After that you should be able to copy and paste your code (keeping the original indentation) and Ipython won't add new indentation.
Another solution is using the magic command: %paste This command paste and execute the code from clipboard (here you can find more information about this command).
If you want to edit the code in the prompt before executing it, remember you can use: %cpaste instead.