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.
Related
There appears to be no option for automatic formatting, it slightly irritates me. Perhaps I have OCD:
private void someFunc() {
}
// I want
private void someFunc(){
}
I have tried looking in |options > text editor > C# > code style > formatting| ... to no avail.
In c# formatting is no entirely automatic. You need to press ctrl+k;ctrl+e to format file.
For C# code files, Visual Studio 2019 has a Code Cleanup button at the bottom of the editor (keyboard: Ctrl+K, Ctrl+E) to apply code styles from an EditorConfig file or from the Code Style options page.
Use instruction from here to setup your style
But, if there is a space or no space - you must set in your style setting.
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 am using visual studio 2013, I am using an extension called "Code Alignment". After I apply the alignment and try to beautify the code, the visual studio removes the alignment.
I already checked the options in:
Option > Text Editor:
Tabs
Keep tabs
Do you have a solution for this?
ie:
before formatting:
var previousLowAddress = new string[1];
var previousMedAddresses = new string[1];
var previousHighAddresses = new string[1];
after visual studio formatting:
var previousLowAddress = new string[1];
var previousMedAddresses = new string[1];
var previousHighAddresses = new string[1];
Most likely, the problem is the font you are using is not "monospaced". This means different characters can take different amount of space, which will break the math the CodeAlignment plugin will do for you.
Try changing the Text Editor font to a monospaced type, such as "Consolas".
I tested this locally using Consolas and Microsoft YaHei UI fonts. As expected, the monospaced font (consolas) shows the correct alignment, and the Proportional font (Microsoft YaHei UI) does not.
VS has auto formatting enabled by default for c#. The options are in Text Editor\C#\Formatting.
You may need to disable all option in these category.
The productivity power tools extension also has a feature which formats the document on save. So if you use these extension you may disable the feature.
The built-in c# auto formatting honors indenting assignments, but if you try to indent round brackets/operators (as code alignment does), the extra whitespace will be removed by formatting.
Let's say I have a trivial if statement as follows:
if(a > b)
{
return false;
}
Whilst the above matches my defined coding style perfectly, what I want to be able to do is highlight these 4 lines of code, and then very quickly be convert them into a single line as follows:
if(a > b) { return false; }
Is there a way of doing this selectively. I do not want to do it throughout the file - only the lines I highlight. In many cases I will want the if statement left on multiple lines.
I have ReSharper if that helps.
Install the VsVim Extension and then you can place your cursor on the if keyword and then press CTRL+ALT+→ twice (assuming you are using the Resharper Visual Studio keymap) to select the whole if block and then press SHIFT+J to join all the lines in to one.
If VsVim is not for you then you could try the CodeMaid Extension that adds join line functionality (using CTRL+M, J)
You can create a custom template. Take a look here. You can then have the standard Resharper fix for the lines you suggested and apply them where you want.
Is there a way in visual studio to get braces to indent when editing javascript.
Though there is an option for it in Options under Text Editor:C/C++:Formatting:Indent Braces but for the JScript Text Editor it does not list the 'Indent Braces' as a Formatting option.
How could I accomplish this so that our c++ and js code are consistently formatted? We use whitesmith style for majority of the code
Whitesmith style looks like:
if (condition)
{
statement();
}
Would there be a way with VS extensions or options to do this?
Any leads/solutions are appreciated.
In Visual Studio 2010, go:
Tools > Options.
Expand the Text Editor node and select JScript. (a.k.a JavaScript).
Under Formatting, tick the "Place open brace on new line for functions" checkbox.
You cant do this with Visual Studio. A tool like Resharper can do this for you.
IF you gave up on finding a good tool copy and past you code to http://jsbeautifier.org/ it will take you few seconds to clean up your javascript mess doing it this way
I like Resharper and agree with Valamas that it allows you to define style of formatting of the code much more fine as Visual Studio. I decide to write my answer because of another problem.
Every language has his standards. Sometimes formatting is not only the matter of taste. JavaScript can automatically insert of semicolons in some situations it the code on the next line can be interpret as the separate block statement. For example the line
return
{
statement();
}
will be interpret as
return; // return undefined;
{
statement();
}
It is the reason why all professional developed JavaScript code use Kernighan and Ritchie Indent style (K&R style):
return {
statement();
};
It is not important which formatting style you use in another language which you mostly use. If you write code in JavaScript I would you strictly recommend to follow K&R style in all parts of your JavaScript code:
if (condition) {
statement();
}
You can read more about semicolon insertion here or in 7.9.1 of ECMA-262 (also here)