Reputation: 65
I'm new to Visual Studio Code and I have moved there from Atom since I'm learning C#. This is also my first time posting a question here, so pardon me if I haven't done a good job.
for(int i = 1; i < args.Length; i++){<cursor>}
I want to be able to press enter and the code should look like:
for(int i = 1; i < args.Length; i++)
{
<cursor>
}
I know other people have faced similar problems but I've researched for hours and fiddled around with the setting to no success. I am using Visual Studio 2017, latest version.
Please ask questions if you need any more information. Thanks!
Upvotes: 2
Views: 1842
Reputation: 65
Thank you for all the feedback guys, I managed to fix it.
In Tools > Options > Text Editor > C# > Tabs:
I had switched to Block (from Smart) because Smart Tabs made the ending curly brace go all the way to the left. I tried switching it back and forth, but it didn't solve the problem.
I was reading up on another issue where the person who asked the question added a comment saying that new files didn't have the issue. So, I tried this with the original settings on a new file and it worked without a problem :)
Sorry for the trouble, thanks once again for all the tips!
Upvotes: 1
Reputation: 1377
Unfortunately, the format you have it in is valid pretty much all the time. Looks like it's been minified, so it'd be acceptable by my standard.
I guess you're doing this on mass and looking for a quick way to do it.
If you press Ctrl + H, it should open the search replace dialog.
Turn on the regex expression feature. (little box under the search box which has something that looks like an asterix)
In the search box, input: "for\((.)\){(.)}"
In the replace box, input: "for ($1) \n { \n $2 \n }"
This uses regular expressions to sort out the issue your having. By the way, that will only work for for loops in the exact format you've described, which looks like it's been minified so it should be fine.
So yeah, if you press enter, it should take you to all the for loops. After that, just click replace all and it should be in the format you desire.
Afterwards, your indentation will likely be all out of whack, so just doing Ctrl + K, then Ctrl + D, should sort that all out for you.
By the way, I'm no regular expressions connoisseur, so please don't berate me for my amateur skills.
Upvotes: 0