I'm using VS 2015 and when I press enter after a code line when writing javascript I always start the next line at the beginning. I would like it to start at the "proper" place, for e.g.
function newLine() {
Starts here..//Works fine
}
Starts here now..
EDIT: By "Should start here.." I mean one tab in from the braces, not two lines below :)
Tools -> Options -> Text Editor -> -> Tabs -> Indenting To BLOCK.
VS 2015 suddendly stopped indenting properly for me. I was able to solve this by going to Tools/Options/Text Editor/"language of choice"/Tabs and selecting smart indenting
Tools -> Options -> Text Editor -> Choose your language -> Tabs -> Indenting -> Smart
Finally you must restart the Visual Studio(all instance).
Related
If I comment out a block of code using the comment comment (Ctrl+E,C) and then uncomment (Ctrl+E,U) then the code is reformatted based on whatever options are set for things like braces in new lines, spacing around brackets, etc.
Is there any way to disable this behaviour and just leave the code as it was?
I don't recall seeing this behaviour prior to Visual Studio 2015.
OK I just found the relevant setting:
Tools -> Options -> Text Editor -> Basic -> Advanced -> Pretty listing (reformatting) of code
In Visual Studio 2013, under Tools > Options > Text Editor > File Extension, I have set three file extensions, namely .cginc, .compute, and .shader (these are Unity3D shader files) to use Microsoft Visual C++ for auto formatting.
Sometimes auto indent (for curly braces) works, and sometimes it doesn't...I can't find any rhyme or reason for this. When it doesn't work, it starts every new line flush to the left.
I Google around every couple weeks and can't find an answer.
Does anyone know any setting to make auto indent work consistently?
Try this:
Tools -> Options -> Select the language of your choice (Expand the menu) -> Select Formatting (Expand this sub menu) -> Select Indendation
Once you have selected Indentation, on the right are options displayed - Check/Tick the option: Indent Braces.
Note: You may also format the entire document/file using the shortcut Ctrl+K+D
Ok - I want indenting turned off in Visual Studio Pro 2013, so...
Tools -> Options -> Text Editor -> All Languages -> Tabs -> Indenting (set to None) -> Click OK
Now, no matter what type of file I edit I get indented text, code, comments; I have indents coming out of my ears !
It's a cruel joke right? Or am I the only person who thought setting Tabs -> Indenting to None meant none?
What magic am I missing? -- and yes, I have found similar posts and NONE (sorry for the pun) of the solutions have worked yet ...
Seriously though -- I know I missed some setting -- but for the life of me I cannot disable this behavior.
I started playing around with javascript on Visual Studio 2013 and I couldn't figure out why it is not automatically positioning the cursor to the correct indentation level, instead always resetting back to the head. For example:
function foo(y) {
var f = function bar(x) {
|<-- cursor should be here, but ends up
|<-- over here
}
Does anyone else see this and how do you change it?
I have the typescript, nodejs plugin installed and that's about it.
With a bit of research, things started working for me. First check that, Tools -> Options -> Text Editor -> Javascript -> Tabs -> Indenting is set to 'Smart'. Next restart VS. For me restarting was important since, apparently, my file had some mixed line-endings and that was throwing off the indentation engine. Hope this helps someone.
In my case, the whole javascript formatting stopped working for every file, I could play with language options and restart VS, nothing helped, until I unchecked:
Tools -> Options -> Text Editor -> JavaScript/TypeScript -> Language Service -> Enable the new JavaScript language service
The editor returned to old school javascript formatting, which is sufficient for me.
I'm not sure if this applies to Visual Studio 2013 (the original question), but in 2015 at least, you can select the text in your JavaScript file you want to format, right-click, and then choose "Format Selection". There's a keyboard short-cut as well (Ctrl-K, Ctrl-F).
If you already have Tools -> Options -> Text Editor -> Javascript -> Tabs -> Indenting set to 'Smart', then try setting this option (the Indenting setting) to 'None' and click OK.
Open the Options back up and, set Tools -> Options -> Text Editor -> Javascript -> Tabs -> Indenting back to 'Smart', click OK.
Close and reopen the file you were working on.
Trying to get my css / C# functions to look like this:
body {
color:#222;
}
instead of this:
body
{
color:#222;
}
when I auto-format the code.
C#
In the Tools Menu click Options
Click Show all Parameters (checkbox at the bottom left) (Show all settings in VS 2010)
Text Editor
C#
Formatting
New lines
And there check when you want new lines with brackets
Css:
almost the same, but fewer options
In the Tools Menu click Options
Click Show all Parameters (checkbox at the bottom left) (Show all settings in VS 2010)
Text Editor
CSS
Format
And than you select the formatting you want (in your case second radio button)
For Visual Studio 2015:
Tools → Options
In the sidebar, go to Text Editor → C# → Formatting → New Lines
and uncheck every checkbox in the section "New line options for braces"
For Mac OS users:
Preferences → Source Code → Code Formatting → choose what ever you want to change (like C# source code) → C# Format → Edit -→ New Lines
Tools -> Options -> Text Editor -> C# -> Formatting -> New Lines -> New Line Options for braces -> Uncheck all boxes.
The official MS guidelines (at the time in 2008) tells you to have the curly brace on the same line as the method/property/class and many other things which are not enforced in Visual Studio.
You can change all these auto-text settings under:
Tools -> Options -> Text Editor -> [The language you want to change]
UPDATE: This was based on the book "Framework Design Guidelines" written by some of the core-people from the .NET-team. If you look at the source-code for the likes of ASP.NET MVC, this is no longer accurate.
Go to Tools -> Options -> Text Editor -> CSS -> Formatting. Click "Semi-expanded," which matches the style you defined.
For CSS you'll need the 'Semi Expanded' option.
For Visual Studio Mac OS (Community edition) version 8.3 you need to do the following:
Preferences -> Source Code (in left menu) -> Code Formatting -> C# source code -> C# Format -> Press Edit
Select New Lines from the Category dropdown menu:
Deselect each option in the New line options for braces:
There is a specific formatting setting in VS 2008/2010 to keep the open brace on the same line:
Click Tools->Options Select 'CSS' within 'Text Editor' tree node Select 'Formatting' under 'CSS' node Click 'Semi-expanded' radio button
You will see a preview what the various radio buttons avail will do to the formatting
If you're looking for this option within Visual Studio 2014, then it's under advanced and is now a 'Brace positions' drop down box: