Can't minimize commented code in Visual Studio - c#

Visual Studio (2019) The plus / minus box on side of screen no longer appears so that I can minimize blocks of code that I comment out
Here is an image where the plus bar shows up where I have minimized my code for a function
but I have nothing showing up for the /* that is later in the picture
Edit:
Apparently, The comments will minimize outside the c# classes and methods but not inside them:Commentable Code vs UnCommentable Code
If there is a way to change this please post an answer!

You could set Collapset in Tools->Environment->Keyboard.
Ctrl + M, Ctrl + O: Collapse all in the document
Ctrl + M, Ctrl + M: expand/collapse at the caret
Ctrl + M, Ctrl + L: expand all documents

Tools -> Options -> Text Editor -> C# -> Advanced
Is this checkbox checked?
Show outlining for comments and preprocessor regions
Here is what I have in my VS 2017. Do you use any add-ins that may interphere?
NEW OBSERVATION:
The comment outlining works at the global scope, namespace and class, but NOT in the method!
C# style comments (triple slash ///) work in methods, too.

Related

How can VS2017 + Resharper surround selection with quotes when open quote typed?

I use Visual Studio 2017 with Resharper Ultimate 2018.1 on Windows 10 to assist my coding in C#.
I enabled "Surround selection on typing a brace or paranthesis" under Resharper options. It now surrounds the selected text with () if I type ( or with {} if I type {.
I want this behavior to act similar for single quotes, double quotes and braces as in 'selection', "selection", [selection].
All the solutions I found online use some sort of keyboard shortcut or context menu actions. It is too cumbersome to use combo keys or a mouse action to simply surround a code piece with quotes. Visual Studio for Mac supports this feature out of box. Am I missing something here?
You need to create a template in Resharper for that
Go to ReSharper -> Tools -> Template Explorer -> Surround Templates -> C#
and create new
Now if you go to your code and type
var a = 4444;
Then select 4444 and press Ctrl E+ Ctrl U you will see the following
The result is
var a = "4444";
Select your text and press double quote ", which is Shift+2 on my keyboard, and you'll get quotes around your selection.
It doesn't seem to work with single quote '. Or at least, I couldn't figure it out.

Visual Studio Code Review Difference Window

When I was doing C# code reviews at first in VS 2012 I was getting a side by side comparison of the old and new code.
However now I am getting all code in the same window with red lines for old code and green lines for new code.
I cannot find the option to change this back to a difference window.
I know this is a simple issue but any help will be greatly appreciated!
There should be a button on the toolbar like this one that will let you select the 4 different "diff modes".
You can also use the following keyboard shortcuts:
Ctrl+\, Ctrl 1 - Inline
Ctrl+\, Ctrl 2 - Side-by-side
Ctrl+\, Ctrl 3 - Left Only
Ctrl+\, Ctrl 4 - Right Only
to change the view.
Below screenshot will help in setting the option to compare side by side.

How to jump to the region header from the endregion tag in c# visual studio 2012?

If i have the following
#region
blah;
blahblah;
.....
moar;
#endregion
how can i jump to the top #region label if i see the #endregion tag on my screen?
Is there a short cut?
Ctrl+] will jump between the start and end of blocks. I just tested, and it works for #region blocks for me in VS2010.
Edit: The relevant command is Edit.GoToBrace
The answer is Ctrl + ] as already answered by #TheEvilPenguin.
But I thought to add this awesome link for other shortcuts as well, which can be helpful in speeding up routine tasks in VS.
Save the link page as html in your system, as the link might expire in future.
For Visual Studio 2015, Ctrl + ] doesn't work anymore. But you can use the following:
Click on region
And use following shortcuts: Ctrl + shift + ↑ and Ctrl + shift + ↓
I don't believe there's a standard shortcut in Visual Studio.
Within Visual Studio's options dialog, I did a search through all available commands for anything containing the word "region":
But didn't find anything related to navigation, just expand/collapse.
Addins like Resharper and CodeRush may give you what you want, if you have the budget for it. (And they do a lot more besides.)

VS 2010 "Go to Top of Page" Shortcut

I looked around and googled but did not find any "Go to Top of Page" Shortcut on VS 2010.
This is very frustrating when your class is 2000 lines long and you want to scroll to top.
Anyone ?
Ctrl + Home, it's a convention in windows application (works with any text editor: Word, Notepad, etc.)
Not sure how to do it with any mouse shortcut.
But, with keyboard you can do it with Ctrl + Home
By the way - with mouse, in case you want to reach to the top of the defined Class in filename.cs file, you can goto left top combobox in your class file and select the class name and it will take you to top of that selected class name as in below screenshot:
Ctrl+Home
It's like any other windows doc

How to permanently disable region-folding in Visual Studio 2008

Anyone know how to turn off code folding in visual studio 2008? Some of my colleagues love it, but I personally always want to see all the code, and never want code folded out of sight. I'd like a setting that means my copy of Visual Studio never folds #regionsor function bodies.
Edit: I recommend this other answer
Go to the Tools->Options menu.
Go to Text Editor->C#->Advanced. Uncheck "Enter outlining mode when files open".
That will disable all outlining, including regions, for all c# code files.
The accepted answer turns off ALL code folding. If you want to disable #region folding but collapse comments, loops, methods, etc I wrote a plugin that does this for you.
Make #regions suck less (for free):
http://visualstudiogallery.msdn.microsoft.com/0ca60d35-1e02-43b7-bf59-ac7deb9afbca
Auto Expand regions when a file is opened
Optionally prevent regions from being collapsed (but still be able to collapse other code)
Give the #region / #end region lines a smaller, lighter background so they are less noticeable (also an option)
Works in C# and VB (but only in VS 2010/2012, not supported for 2008)
You can also disable region-wrapping on generated code (like when you use the Visual Studio shortcut to auto-implement an interface).
alt text http://dusda.com/files/regionssuck.png
Options / Text Editor / C# / Advanced / Enter outlining mode when files open
It's not permanent, but the keystrokes Ctrl-M Ctrl-L expand the regions in a file
Also, a quick way to toggle expand/collapse of all regions is: CTRL + M + L
I've posted an answer in a related-but-not-duplicate thread that may help some people here. I detailed how to create macros that will deactivate a single unit's #regions by commenting out the #region and #endregion directives, with a companion for reactivating them. With the #regions deactivated the Ctrl+M+O / Collapse to Definitions function does exactly what I want it to. I hope this is useful for someone beside myself.
Shortcut to collapse to definitions except regions
This option seem to be available only in C# and not in C/C++ (Visual Studio 2005). To disable outlining in C/C++ files you need to make a trick by changing the outlining color to editor's background color. To do this go to Tools > Options > Environment > Fonts and Colors > Collapsible Text > Change "Item Foreground" color to White (or whatever your background color is).
i resolved the problem for me with an environmentevent:
start macroeditor (alt+f11)
open macroproject / EnvironmentEvents
paste the follwing code:
Private Sub DocumentEvents_DocumentOpened(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentOpened
If (Not Document Is Nothing) Then
If (Document.FullName.ToLower().EndsWith(".cs")) Then
Try
DTE.ExecuteCommand("Edit.ExpandAllOutlining")
Catch ex As Exception
End Try
End If
End If
End Sub
Private Sub WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, ByVal LostFocus As EnvDTE.Window) Handles WindowEvents.WindowActivated
If (Not GotFocus Is Nothing) Then
If (Not GotFocus.Document Is Nothing) Then
If (GotFocus.Document.FullName.ToLower().EndsWith(".cs")) Then
Try
DTE.ExecuteCommand("Edit.ExpandAllOutlining")
Catch ex As Exception
End Try
End If
End If
End If
End Sub
Greetings
Tobi

Categories