7

Is there a way to lock or freeze a part of code against formatting in Visual Studio?

I want to protect the following code :

Method("This is a long text", 12 , true  );
Method("Hi",                  558, true  );
Method("Short text",          1  , false );

to be formatted as:

Method("This is a long text", 12, true);
Method("Hi", 558, true);
Method("Short text", 1, false);

but still be able to format the rest of the document.

5
  • do you mean when you for instance push ctrl-k ctrl-f for "format file" that you want to skip these lines?
    – default
    Feb 15, 2013 at 13:00
  • It's no duplicate because I constantly use formatting. I don't want it off. Just want to freeze that part Feb 15, 2013 at 13:02
  • @Default ctrl-k ← for bookmark ctrl-f ← for find/search
    – spajce
    Feb 15, 2013 at 13:04
  • 1
    He means ctrl-k ctrl-d Feb 15, 2013 at 13:06
  • 1
    As others have said - there's no built-in way of doing this. Additionally, since it is a very specific case, why not move that code into a separate Source_Unfmt.cs file.
    – Jesse
    Feb 15, 2013 at 17:09

2 Answers 2

0

You can turn it off completely (Options->TextEditor->Basic->General) uncheck off Pretty Listing. And under Options->Text Editor->C#->Formatting turning off options there.

But, sadly, there isn't any built-in option to selectively prevent formatting a portion of code.

2
0

The ReSharper formatting style, is the key for your problem.

3
  • Can you post link to some screenshot from formatted code by ReSharper ? Feb 15, 2013 at 13:13
  • 1
    Resharper has LOTS of options for formatting. But not for protecting one section of code. (stackoverflow.com/questions/2090354/…)
    – hometoast
    Feb 15, 2013 at 13:16
  • it might be this feature will be added is in another version. we will wait :)
    – spajce
    Feb 15, 2013 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.