简体   繁体   中英

Visual Studio 2015 - C# line break behavior after snippets

Since I've upgraded to Visual Studio 2015, an annoying, even frustrating, behavior has manifested. This occurs whenever I enter some kind of snippet (such as an if block by typing "if" followed by [Tab][Tab], or perhaps highlighting some code and using the "Surround With..." option). When I click after the closing bracket of said snippet and then hit [Enter], I would expect a line break to occur, resulting in something like this:

if (true)
{
    // some code
    // some more code
} // (right here, after the closing bracket, is where I clicked, then hit [Enter])
// new empty line

Instead, the line break does not occur, and the text focus is moved to inside the block after the last line of code, like so:

if (true)
{
    // some code
    // some more code (text focus is now right here)
}

I notice no prompts whatsoever when this behavior occurs, leading me to believe this isn't some "smart" feature that is configurable. Is anyone else experiencing this? If so, what can I do to troubleshoot this?

EDIT:

User42's answer below resolved the issue for me, but here is a video of the issue taking place for those who are experiencing the same thing.

Reproduced with VS2015.

The reason is that you are still in the middle of filling out the argument for the if (see that it is highlighted). Just type the argument and click enter to let VS know you're done. It's a feature, not a bug. :)

Another option would be to edit the snippet. The snippets are stored in:

C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC#\\Snippets\\1033\\Visual C#

I advise you to first make a copy of a snippet before editing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM