Visual Studio incorrectly smart indents the opening brace - visual-studio

When I type the closing brace in an html page, this i what Visual Studio does. Notice the opening brace is now 1 indent before the foreach. They should be even as shown by the closing brace. Not a big thing but driving me nuts.
<% foreach (var item in Model.Messages)
{ %>
<% } %>

Go to Tools -> Options -> Text Editor -> [Pick your language] -> Formatting. You should find something in there.

In code view press Ctrl+E,D It will auto-format/indent your code.

When I try Ctrl+K, Ctrl+D in Visual Studio 2010 Express, it says this key combination is bound to the command (Format document) which is not currently available.

Related

How to wrap selected code in brackets/parentheses in Visual Studio 2022

In VS Code and JetBrains IDEs, when you select (highlight) a snippet of code and press an opening key for brackets ({ or [) or parentheses ((), it wraps the selected text. Visual Studio, however, deletes the selected snippet, or better, replaces it by the pressed character. Is there a way to configure it to the more intelligent behaviour of VS Code and JetBrains? I browsed "Text Editor" settings but didn't find any that seemed to do this:

Visual Studio: how to stop IntelliSense appearing after quote in HTML editor?

In HTML editor in VS 2013, when I am inside a paragraph and type ' or ", some snippet dropdown appears:
Is there a way to prevent this behavior?
This is probably not a VS-thing but a bug in WebEssentials. I've reported it to the team.

Visual Studio uses XHTML tag closing for HTML5 tags

Whenever I type out tags that don't require an end tag, Visual Studio adds a forward slash to it, as if they were XHTML.
I think this is unclean and annoying, and I'm hoping anyone can tell me how to fix or work around this issue.
It even happens when I complete <!DOCTYPE html with a >, and it'll form <!DOCTYPE html />.
For completeness I'm posting this answer. Although we're in 2014 now, with Visual Studio 2013 and HTML5 is getting more and more supported by the major browsers, Visual Studio still behaves the same as ... like always?
The option is just a bit different than in 2010 I assume (based on accepted answer).
What you could do is disable the auto closing tag option in Visual Studio.
Go to Tools >> Options >> Text Editor >> HTML >> Formatting
Uncheck the "Auto insert close tag" option.
This will now allow you to type <br> (for example) and it won't auto-complete it as <br />
For Visual Studio 2012, go to Tools -> Options -> Text Editor -> HTML -> Formatting and click Tag Specific Options.
Under Default Settings -> Client tag does not support contents, set Closing tag to No closing tag.

Show space, tab, CRLF characters in editor of Visual Studio

Where are the settings to show a space, tab, paragraph, CRLF, etc. (extended) characters?
Edit > Advanced > View White Space. The keyboard shortcut is CTRL+R, CTRL+W. The command is called Edit.ViewWhiteSpace.
It works in all Visual Studio versions at least since Visual Studio 2010, the current one being Visual Studio 2019 (at time of writing). In Visual Studio 2013, you can also use CTRL+E, S or CTRL+E, CTRL+S.
By default, end of line markers are not visualized. This functionality is provided by the End of the Line extension.
Edit -> Advanced -> View White Space or Ctrl+R,Ctrl+W for Visual Studio 2019
Display white space characters
Menu:
You can toggle the visibility of the white space characters from the menu:
Edit > Advanced > View White Space.
Button:
If you want to add the button to a toolbar, it is called Toggle Visual Space in the command category "Edit".
The actual command name is: Edit.ViewWhiteSpace.
Keyboard Shortcut:
In Visual Studio 2015, 2017 and 2019 the default keyboard shortcut still is CTRL+R, CTRL+W
Type one after the other.
All default shortcuts
End-of-line characters
Extension:
There is a minimal extension adding the displaying of end-of-line characters (LF and CR) to the visual white space mode, as you would expect. Additionally it supplies buttons and short-cuts to modify all line-endings in a document, or a selection.
VisualStudio gallery: End of the Line
Note: Since Visual Studio 2017 there is no option in the File-menu called Advanced Save Options. Changing the encoding and line-endings for a file can be done using Save File As ... and clicking the down-arrow on the right side of the save-button. This shows the option Save with Encoding. You'll be asked permission to overwrite the current file.
My problem was hitting CTRL+F and space
This marked all spaces brown. Spent 10 minutes to "turn it off" :P
The correct shortcut is CTRL-R-W like you don't have to release CTRL button while pressing W. This worked for me in VS 2015
For those who are looking for a button toggle:
The name of this command is View white space in GUI menu (Edit -> Advanced -> View white space).
The name of this command in the Add command popup is Toggle Visual Space.
If you use Visual Studio Code => View => Render Whitespace
That's it!
For me this setting was on, but didn't work. I had to turn it off and on again and than it worked! So this is a bug in Visual Studio Code!
If you use Visual Studio 2022 you can change the display options for whitespace etc. in Tools => Options => Text Editor => General and select "View whitespace"
The shortcut didn't work for me in Visual Studio 2015, also it was not in the edit menu.
Download and install the Productivity Power Tools for VS2015 and than you can find these options in the edit > advanced menu.
To see the CRLF you can try this extension: End of the Line
It works for VS2012+
For Visual Studio for mac, you can find it under Visual Studio -> Preferences -> Text Editor -> Markers and Rulers -> Show invisible characters
Please note you may need to restart Visual Studio for the changes to take effect
For completeness since I haven't seen it mentioned here, it is also in Options->Text Editor->General->View Whitespace.
In the actual version this Option ist under Editor: Render Whitespace

Why does the Visual Studio editor show dots in blank spaces?

I have a strange bug in the Visual Studio text editor.
All my blank spaces are replaced by a "."
public class Person
{
int age;
}
looks like this
public..class..Person..........................
{..................
..int age;...................
}.....................
I reset the settings to default. Didn't work.
I also re-installed VS2008. Still didn't work.
What's the error?
Visual Studio is configured to show whitespace.
Press Ctrl+R, Ctrl+W.
If you are using C# keyboard mappings: (thanks Simeon)
Press Ctrl+E, S.
If you want to use the menu: (thanks angularsen)
Edit > Advanced > View White Space
Looks like you have the view white space option enabled. Go to Edit -> Advanced -> and uncheck "View Whitespace"
In Visual Studio 2012
Go to
Edit -> Advanced -> View White Spaces
Or
Press Ctrl+R, Ctrl+W
~ FOR VISUAL STUDIO 6 ~
use: ctrl+shift+8
to toggle on/off.
(or manualy go to: Edit> Advance > "View Whitespaces")
goodluck!
Works also for Visual Studio 2008, when
Tools/Options/Environment/Keyboard/Mapping Scheme: Visual C++ 6
is selected.
Please press below buttons in combination of
Ctrl + R,W
I had the same problem and resolved by pressing Ctrl + R , Ctrl + W.
In Visual Studio vesrion 1.34.0 View -> Toggle Render Whitespace
Press ctrl + E followed by S key to remove the lines in Visual Studio 10
go to File -> Preferences -> Settings, this will open two panels side by side, the left one is default setting and the right one is user setting, you can add your setting on right panel, for this you can add "editor.renderWhitespace": "all".
In visual studio 2015, goto->view->formatting marks, unselect show
In Visual Studio 2019, this can also be configured in Tools -> Options -> General -> View whitespace

Resources