Locil
Locil

Reputation: 33

C# Visual Studio 2015 - Automatic jump into brackets

This is my first question on stackoverflow, so here goes:

I've got this annoying problem/feature in Visual Studio 2015. The problem is every time I create an if statement, for, while, etc. with autocomplete (tab-tab). When I then go to the line of the end bracket and try to create a new line (simple press of Enter) right after it, my text cursor will immediately jump into the brackets, instead of making a new line.

I've looked far an wide as for trying to disable this "feature" as it is incredibly annoying. But I have not been able to find any information on it anywhere, so now I am asking you all this question.

Thank you!

How I produce the problem:

  1. Anywhere in a C# project, make a new if statement (while, for, etc. can be used too).
  2. Navigate to just after the end bracket.
  3. Press Enter to make a new line.
  4. The marker will have jumped to the inside of the statement, instead of making a new line.

Upvotes: 3

Views: 566

Answers (1)

Sergio Acosta
Sergio Acosta

Reputation: 11450

The 'problem' is that when using the tab key you are activating the snippets feature. After typing tab you are in 'snippet editing' mode, where each tab (and shift + tab) are used to navigate the placeholders defined by the snippet. In snippet mode, the Enter key always takes you wherever the person who designed the snippet thought it was the best place to leave the cursor after that snippet. For the if snippet that happens to be inside the brackets.

The good news is that you can create your own snippets, and even modify existing snippets to change their behaviour. However, as far as I know this involves manually editing snippet definition files (xml files) or using external extensions. For example: http://blogs.msdn.com/b/visualstudio/archive/2014/01/15/visually-creating-snippets.aspx

As a workaround, you can also just press Esc to exit snippet editing mode before pressing Enter.

Upvotes: 4

Related Questions