views:

97

answers:

3

In VS 2008, there are XML code snippets that seem to be pretty awesome :) However, it seems that the snippets we created do not indent properly. For example if we have the following code:

{
   ...
   { 
   ...
       {
          InsertSnippet here.

We get something like:

{
   ...
   { 
   ...
       {
          FirstLineofSnippet
SecondLineOfSnippet
ThirdLineOfSnippet

Is there any way to make it so that all lines keep the same indentation?

A: 

paste the first line without indentation, then select the block and tab until you get the whole block to the indentation you want. AFAIK what you see is the standard behavior and it happens because the location you paste from wasn't indented as far as you wanted.

abc
A: 

My unit test snippet appears to be indenting correctly. It may be due to the fact that the code is wrapped in a CDATA block. VisualStudio also tends to auto-format the block as soon as it is added to the code. Does your snippet have as many open braces as closing ones? If the two match up, and the snippet is inserted in a valid/compilable location, it should auto-format.

Pedro
A: 

Try swithing from 'Insert spaces' to 'Keep tabs' in Tools > Options > TextEditor > C# > Tabs, it worked for me.

Viktor