Paste code without unfolding

When I make a big change to my code, I begin by copying and pasting it into a new window so I still have the old code if something goes wrong. 
I have all my function definitions folded because the code is massive. When I do a paste everything gets unfolded and it takes forever to fold it back how it was. The weird thing is every now and then when I paste it actually does preserve the way it is folded and I can't figure out how. 
Simple pasting or changing my "reformat on paste" settings does not help. Doing a "fold all" also doesn't help because it folds everywhere in the code that is indented which is annoying and worse then just having nothing folded at all. 
Any ideas on how to make it stay folded every time?

Please sign in to leave a comment.