visual-studio-2019intellisenseindentationautoformatting

visual studio 2019...newline after leading comma


I've this notice an annoying behavior from Visual Studio (possibly the Intellisense) and am wondering if anyone knows how to disable it.

Here's what I am trying to do

TheoryData<string> TestData = new ()
{
    { 'hello' }
  , { "world" }
};

Whenever I copy , { "world" } and paste, Visual Studio does this:

,
{ "world" }

Then I have to go in to remove the newline and the spaces.


Solution

  • In short:

    Uncheck "Automatically format on paste" option in Tools > Options > Text Editor > C# > Formatting > General will work, and further, consider unchecking "Automatically format block on }".

    Analyzing:

    Focus on this two options(in Tools > Options > Text Editor > C# > Formatting > General):

    1). Automatically format on paste

    2). Automatically format block on }

    Just uncheck Automatically format on paste option will make your issue("whenever I copy XXXX and paste, XXXXX") resolved.

    But under this circumstance, if you don't copy -> paste, instead, manually type "," and then "{}", the issue will appear again. I mean, you will see that the new brace automatically format in a new line.

    To resolve this, there is another option => Automatically format block on }, uncheck this option will avoid auto complete feature which formats open brace to a new line.

    But you need to consider whether you prefer this, as normally "Automatically format block on }" is useful, and "Automatically format on paste" is also useful.