Hi, I have these settings for comments in Visual Studio 2017:
1) two comment bars '//' (dark green in the image) to indicate 'normal comments'.
2) three comment bars '///' (light green) for special notes and titles.
I find this technique very useful to mantain a clearer code, and I would like to apply the same logic (having similar color settings) in Visual Studio Code.
But I can't figure it out how to do it.
No. You got it wrong. Tripple slash comment is for documentation generation. It is NOT meant for coloring. When it is used with the proper tags, the compiler autogenerates the relative documentation/tooltips:
<summary>Open the connection.</summary>
public void Open()
{
.
.
.
}
Later, when one is accessing the Open() method in Visual Studio, in addition to the intellisense, a tooltip is shown, with the text "Opens the connection."
AFAIK, there is no such thing as a "coloring of a comment". Nor there are "different comments". What do you mean by that?
If you're looking for a way to order your commenes, you might find useful, to structurize them by using a "comment token", thus making the comment appear on the Visual Studio's Task List. Also, you can create your own tokens. From the menu, open the Tools -> Options dialog; choose Environment => Task List from the list on the left.
So somewhere in you code you might do this:
// TODO: Either delete or uncomment the next line.
// settings.decorared = false
Then you'll see the TODO note in your Task List, but not the //settings.decorated.
Hint: To display the Task List press Ctrl+\,T.
You can change the comment color by going to:
Tools | Options | Environment | Fonts and Colors | Comment
I hope my question is clear enough. I am using free version of visual studio express.
When I create a function, there is that "-" or "+" sign next to line number where function is created, which allow me to hide it.
I want to do same thing for my object which is really long because it is storing alot of items. All items are sorted by area, and group which looks like this:
var itemTable = {
groupA: {
BanditHideout: {
itemDrop: [
//Weapons
{
After all items are listed, there is next area and inside it another item list.
Once all areas are done, we move on to groupB and do the same thing, and there are like 10 groups in total each having 5 areas.
I managed to do it manually using "outlining" option in visual studio, where I mark a whole text and press "Ctrl + M" and then "Ctrl + H" which hide the content and create "+" sign next to line number.
I do that for every part i want to hide, and it works well. My problem is that, I have to do it manually which is bad, because for some reason, sometimes all "+" dissapear, and I am forced to do it all over again.
I hope that I am clear enough and you can help me out somehow :) Let me know if you need more information. I can give you a screenshoot if that will help. Thanks for help in advance
You can always use regions :)
#region RegionName
[some of your code]
#endregion
PS. Well, apparently not always ;]
PS2. Since Visual Studio Community edition has been released, there really is no need for VS Express anymore - it lacks wayy too many features compared to the standard version.
BUT - if you're coding only in JavaScript, I'd consider some other, "lighter" IDEs than Visual Studio (off the top of my head - Eclipse or NetBeans, but there's tons of other free IDEs out there).
This question already has answers here:
Is there a way to highlight the currently active code block in Visual Studio 2010?
(4 answers)
Closed 9 years ago.
I'm currently using Visual Studio 2010 (and also have a copy of Visual Studio 2005 which I'm also happy to use if the functionality is available in it but not '10)
What I'm wondering is if there is any way to highlight pieces of code?
For instance, I'm currently working on an assignment to take a piece of code, and change the stack implementation. It would be really useful if I could highlight the stack implementation specific pieces of code so that it's easy for me to just glance at the screen and know which pieces need my attention rather than having to visually wade through it.
(I am using comments to highlight the stack implementation specific code - but they get a little lost amidst other comments - and this seems like a better idea.)
You might consider using bookmarks at the start of a section you are interested in, or on a specific line. While this does not highlight the lines of code, it does provide a visual indicator in the left margin.
If you use the AllMargins extension, it also appears there. This is a handy way to quickly see if there any bookmarks in the current document, and also helps since the bookmark icon on the left will not appear in collapsed regions.
By using bookmarks, you can also use the bookmarks window to quickly navigate to the code you are interested in:
Consider using #region and #endregion blocks.
From MSDN:
#region lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor. In longer code files, it is convenient to be able to collapse or hide one or more regions so that you can focus on the part of the file that you are currently working on. The following example shows how to define a region:
#region MyClass definition
public class MyClass
{
static void Main()
{
}
}
#endregion
For smaller sections / individual lines of code a quick way to jump between or keep track of them is to use Bookmarks. These can be added by using Ctrl+K, Ctrl+K and you can press Ctrl+K, Ctrl+N to move to the next bookmark, or Ctrl+K, CTRL+P for the previous bookmark. The Navigating Bookmarks article is a good quick reference.
I wish to disable all code formatting in Visual Studio 2010, with the intention of selectively switching options back on as I see fit.
Currently I have a specific problem that refuses to go away; When I add the final brace in the code block below, Visual Studio 2010 reformats the code for the entire switch statement above that point, placing each line against the margin (removes leading whitespace on each line). I've switched off every setting in Tools/Options/C#/Formatting to no avail. Is there an overriding 'Disable all formatting' option? Thanks.
switch(fractionalDigits)
{
case 0:
if(significand > 107374u)
{
if(truncateRange)
{
significand = 1073741823u;
}
else
{
result = FixedPointDecimal.Null;
return false;
}
}
else
{
UPDATE: The specific problem above was caused by additional formatting options being added by the Power Tools. The additional formatting options seem to interact with the built in logic an odd way.
Tools > Options > Text Editor > C# > Formatting > Indentation > Indent case labels
You could try the following:
Create a color theme with nearly no color. So you could readjust each code elements color step by step.
You can use the following tool to generate a no color theme:
Theme generator
Set the constrast to the left and main and foreground color to white.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
Visual Studio is such a massively big product that even after years of working with it I sometimes stumble upon a new/better way to do things or things I didn't even know were possible.
For instance-
Crtl + R, Ctrl + W to show white spaces. Essential for editing Python build scripts.
Under "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Text Editor"
Create a String called Guides with the value "RGB(255,0,0), 80" to have a red line at column 80 in the text editor.
What other hidden features have you stumbled upon?
Make a selection with ALT pressed - selects a square of text instead of whole lines.
Tracepoints!
Put a breakpoint on a line of code. Bring up the Breakpoints Window and right click on the new breakpoint. Select 'When Hit...'. By ticking the 'Print a message' check box Visual Studio will print out a message to the Debug Output every time the line of code is executed, rather than (or as well as) breaking on it. You can also get it to execute a macro as it passes the line.
You can drag code to the ToolBox. Try it!
Click an identifier (class name, variable, etc) then hit F12 for "Go To Definition". I'm always amazed how many people I watch code use the slower right-click -> "Go To Definition" method.
EDIT: Then you can use Ctrl+- to jump back to where you were.
CTRL+SHIFT+V will cycle through your clipboard, Visual Studio keeps a history of copies.
Sara Ford covers lots of lovely tips: http://blogs.msdn.com/saraford/archive/tags/Visual+Studio+2008+Tip+of+the+Day/default.aspx
But some of my favourites are Code Snippets, Ctrl + . to add a using <Namespace> or generate a method stub.
I can't live without that.
Check out a great list in the Visual Studio 2008 C# Keybinding poster: http://www.microsoft.com/downloadS/details.aspx?familyid=E5F902A8-5BB5-4CC6-907E-472809749973&displaylang=en
CTRL-K, CTRL-D
Reformat Document!
This is under the VB keybindings, not sure about C#
How many times do you debug an array in a quickwatch or a watch window and only have visual studio show you the first element? Add ",N" to the end of the definition to make studio show you the next N items as well. IE "this->m_myArray" becomes "this->m_array,5".
Incremental search: While having a source document open hit (CTRL + I) and type the word you are searching for you can hit (CTRL + I) again to see words matching your input.
You can use the following codes in the watch window.
#err - display last error
#err,hr - display last error as an HRESULT
#exception - display current exception
Ctrl-K, Ctrl-C to comment a block of text with // at the start
Ctrl-K, Ctrl-U to uncomment a block of text with // at the start
Can't live without it! :)
Stopping the debugger from stepping into trivial functions.
When you’re stepping through code in the debugger, you can spend a lot of time stepping in and out of functions you’re not particularly interested in, with names such as GetID(), or std::vector<>(), to pick a C++ example. You can use the registry to make the debugger ignore these.
For Visual Studio 2005, you have to go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio \8.0\NativeDE\StepOver and add string values containing regular expressions for each function or set of functions you wish to exclude; e.g.
std::vector.*::.*
TextBox::GetID
You can also override these for individual exceptions. For instance, suppose you did want to step into the vector class’s destructor:
std::vector.*::\~.*=StepInto
You can find details for other versions of Visual Studio at http://blogs.msdn.com/andypennell/archive/2004/02/06/69004.aspx
Ctrl-F10: run to cursor during debugging. Took me ages to find this, and I use it all the time;
Ctrl-E, Ctrl-D: apply standard formatting (which you can define).
TAB key feature.
If you know snippet key name, write and click double Tab. for example:
Write
foreach
and then click tab key twice to
foreach (object var in collection_to_loop)
{
}
2. If you write any event, write here
Button btn = new Button();
btn.Click +=
and then click tab key twice to
private void Form1_Load(object sender, EventArgs e)
{
Button btn = new Button();
btn.Click += new EventHandler(btn_Click);
}
void btn_Click(object sender, EventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}
btn_Click function write automatically
in XAML Editor, Write any event. for example:
MouseLeftButtonDown then click tab
MouseLeftButtonDown="" then click tab again
MouseLeftButtonDown="Button_MouseLeftButtonDown" in the code section Button_MouseLeftButtonDown method created.
Sara Ford has this market cornered.
http://blogs.msdn.com/saraford/default.aspx
More Visual Studio tips and tricks than you can shake a stick at.
Some others:
The Visual Studio 2005 and 2008 3-month trial editions are fully-functional, and can be used indefinitely (forever) by setting the system clock back prior to opening VS. Then, when VS is opened, set the system clock forward again so your datetimes aren't screwed up.
But that's really piracy and I can't recommend it, especially when anybody with a .edu address can get a fully-functional Pro version of VS2008 through Microsoft Dreamspark.
You can use Visual Studio to open 3rd-party executables, and browse embedded resources (dialogs, string tables, images, etc) stored within.
Debugging visualizers are not exactly a "hidden" feature but they are somewhat neglected, and super-useful, since in addition to using the provided visualizers you can roll your own for specific data sets.
Debugger's "Set Instruction Pointer" or "Set Next Statement" command.
Conditional breakpoints (as KiwiBastard noted).
You can use Quickwatch etc. to evaluate not only the value of a variable, but runtime expressions around that variable.
T4 (Text Template Transformation Toolkit). T4 is a code generator built right into Visual Studio
Custom IntelliSense dropdown height, for example displaying 50 items instead of the default which is IMO ridiculously small (8).
(To do that, just resize the dropdown next time you see it, and Visual Studio will remember the size you selected next time it opens a dropdown.)
Discovered today:
Ctrl + .
Brings up the context menu for refactoring (then one that's accessible via the underlined last letter of a class/method/property you've just renamed - mouse over for menu or "Ctrl" + ".")
A lot of people don't know or use the debugger to it's fullest - I.E. just use it to stop code, but right click on the red circle and there are a lot more options such as break on condition, run code on break.
Also you can change variable values at runtime using the debugger which is a great feature - saves rerunning code to fix a silly logic error etc.
Line transpose, Shift-Alt-T
Swaps two line (current and next) and moves cursor to the next line. I'm lovin it. I've even written a macro which changed again position by one line, executed line transpose and changed line position again so it all looking like I swapping current line with previous (Reverse line transpose).
Word transpose, Shift-Ctrl-T
When developing C++, Ctrl-F7 compiles the current file only.
Document Outline in the FormsDesigner (CTRL + ALT + T)
Fast control renaming, ordering and more!
To auto-sync current file with Solution Explorer. So don't have to look where the file lives in the project structure
Tools -> Options -> Projects and Solutions -> "Track Active Item in Solution Explorer"
Edit: If this gets too annoying for you then you can use Dan Vanderboom's macro to invoke this feature on demand through a keystroke.
(Note: Taken from the comment below by Jerry).
I'm not sure if it's "hidden", but not many people know about it -- pseudoregisters. Comes very handy when debugging, I've #ERR, hr in my watch window all the time.
Ctrl-Minus, Ctrl-Plus, navigates back and forward where you've been recently (only open files, though).
I don't use it often, but I do love:
ctrl-alt + mouse select
To select in a rectangular block, to 'block' boundaries.
As noted in comments,
alt + mouse select
Does just a plain rectangular block.
Here's something I learned (for C#):
You can move the cursor to the opening curly brace from the closing curly brace by pressing Control + ].
I learned this on an SO topic that's a dupe of this one:
“Hidden Secrets” of the Visual Studio .NET debugger?
CTRL + Shift + U -> Uppercase highlighted section.
CTRL + U -> Lowercase the highlighted section
Great for getting my SQL Statements looking just right when putting them into string queries.
Also useful for code you've found online where EVERYTHING IS IN CAPS.
Middle Mouse Button Click on the editor tab closes the tab.
To display any chunk of data as an n-byte "array", use the following syntax in Visual Studio's QuickWatch window:
variable, n
For example, to view a variable named foo as a 256-byte array, enter the following expression in the QuickWatch window:
foo, 256
This is particularly useful when viewing strings that aren't null-terminated or data that's only accessible via a pointer. You can use Visual Studio's Memory window to achieve a similar result, but using the QuickWatch window is often more convenient for a quick check.