How to Turn off auto-formatting when surrounding by #region (VS2008)
I dont like the way VS formats the code so, I've u开发者_开发知识库nchecked all 3 options in Text Editor / C# / Formatting.
I've also checked 'Ignore spaces in declaration statements'. In most cases it works.But when I'm surrounding code by eg. #region I noticed my declarations are reformatted (Removed TABs)
Is it a way to protect against ??
I'm using TABs to align, and have checked Tools -> options -> Text Editor -> C# -> Tabs -> "Keep Tabs"
I use Narrange to format all my files, It reorder methods by name, and group them in regions. Its very nice.
I post this becuase I like very much the way nArrange formats my code, you can also create your own formats as templates to apply them to your code instead.
but if you prefer to use the Vs internal surround function you can go to to snippes folder "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC#\Snippets\1033\Visual C#" edit the pp_region.snippet file and remove the Enter after the $end clause to look like this:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>#region</Title>
<Shortcut>#region</Shortcut>
<Description>Code snippet for #region</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<ToolTip>Region name</ToolTip>
<Default>MyRegion</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[#region $name$
$selected$
$end$ #endregion]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
and by removing the Enter in the las row of section Vs will not longer autoformat your code.
精彩评论