Put an option to disable indentation after pasting code
Vertically line up arguments of a function call. Then copy the block of code. Paste it somewhere else. The allignment which you carefully made is all gone. You have to do the same custom formatting every single place you paste your code.
Unfortunately, there is no way of preventing this in Visual Studio 2015. I checked for a solution on the internet. Most people are complaining about the same problem and there is no cure.
Please provide an option for disabling this behavior.
Andrew Osman commented
You can undo the formatting by hitting Control-Z one or more times.
If your method takes so many parameters they need to be listed vertically, you should consider refactoring it to smaller methods, or use a DTO.
If all the auto-formatting in turned off in settings, my code should stay exactly where I type it...period.
Forget about how I SHOULD be formatting, it boils down to my choices. It I tell the editor "don't do it", I expect it work. In previous versions it worked fine and does not auto-format. Bottom line is, it's broken in VS 2015.
Ctrl-z. Please vote on something important like 64 bit vs.
It is also discussed on GitHub:
Nevertheless it seems that it might take some years to be fixed.
Dinesh ygv commented
Even after unchecking Tools\Options\Text Editor\C#\Formatting\Automatically format pasted code, it still formats after pasting. This could be a bug.
What Kevin said... this option already exists, has existed for years, did you even check the Options panel's Formatting sections? I mean, it's a big thing to check, but it's also the obvious place for this.
William Moussiaux commented
It's 'my' code.
I'll format it however I choose, not how someone else thinks it should be.
The editor should not touch my code unless I say it can.
There's no reason I should have to Ctrl-Z or any other function to undo what I didn't want done to start with.
Kevin Pilch-Bisson commented
Go to Tools\Options\Text Editor\C#\Formatting and uncheck Automatically format pasted code.
I'm sure you have your reasons, but I'm not sure why you'd want to do this. One should use proper formatting and indentation to make the code more standardized and easy to read by other developers who are also used to seeing the code displayed in that way. ;)
Yes, Ctrl+Z fixes it. But why do I have to do it EVERY time?
I would be worried that you are copying and pasting code. Keep your code DRY.
Whenever this happens to me I do Ctrl+Z which undoes the formatting without undoing the pasting.
Does control-z help? Sometimes when I paste, I can press control-z to undo the new formatting, and pressing control-z a second time will undo the paste.