Get correct indentation when pasting in VS Code

Currently there is no known stable solution to this. i myself am searching from weeks now. there are some plugins for paste and indent but they raise different issues in many other things like non-responding paste, slow pasting or no multicursor support.

The VSCode forum has this issue as open from years but they arent very active on it. Please go visit the official issue page and try commenting there, every single one counts and we may get official solution to this. https://github.com/Microsoft/vscode/issues/32320

Additionally you can try below plugins, may work for you.

https://marketplace.visualstudio.com/items?itemName=Rubymaniac.vscode-paste-and-indent https://marketplace.visualstudio.com/items?itemName=gazugafan.vscode-indent-on-paste


Thanks to @Galzor for pointing out the issue. Scrolling through Github issues I got workaround for this issue without any additional extension.

  1. Press CTRL+Z after copy paste. It will give you correct indentation. (It works with PasteOnFormat option disabled.)
  2. Or change editing file's language mode to PLAIN TEXT then paste. (You can find language mode in bottom right corner in VS Code) It will not mess up indentation. Then change back language mode to original again.

Hope it helps someone and gets fixed soon!