views:

173

answers:

1

When using code snippets in Visual Studio that contain multiple lines the following lines will preserve the whitespace that was set in the .snippet file instead of positioning the code relative to the original cursor placement.

When using the foreach snippet you'll get code like this:

    foreach (var item in collection)
{

}

Instead of:

    foreach (var item in collection)
    {

    }

Is there a way to change this behavior? Is there a keyword that needs to be used in the .snippet file?

+1  A: 

The code portion of a snippet file is contained in a CDATA which preserves whitespace. The best thing I can tell you is to go into the file and edit it to suit your needs. Your only other option is to do a quick Ctrl+K and Ctrl+D after you use the snippet to auto-format the code which will fix the indenting.

Andrew Hare
I think you mean Ctrl+K, Ctrl+D, Ctrl+K, Ctrl+C is comment selection.
Phaedrus
Yes thanks! Fixed.
Andrew Hare