Visual Studio Format entire file? - c#

Is there a way to issue a key command to properly format an entire file in VS2008 with CodeRush Express?

Use Ctrl+K+Ctrl+D to format document keystroke
Use Ctrl+K+Ctrl+F to format selection keystroke
It's also possible to set your own keystrokes by opening Options... dialog (select Tools->Options from the menu). In Options dialog select Environment->Keyboard form the tree and set your own shortcuts for Edit.FormatDocument.

You could always go to Tools -> Options -> Keyboard and give the Edit.FormatDocument a new shortcut.
Update You can also see what the Shortcuts mapped to this command are this way.

Ctrl+K,Ctrl+D
This question with answers has a lot of handy tips.

If Ctrl+E+Ctrl+D or Ctrl+K+Ctrl+D or Ctrl+K+Ctrl+F doesn't work for you, try to set below settings:
Tools->Options -> Text Editor ->C# ->Tabs,
make sure `Keep tabs is selected.
Then, go back to your text editor, re-try formatting.
I was really annoyed before, and steps above works for me. hope it works for you guys..

Just select all content of page by Ctrl + A then click Ctrl + K and Ctrl + D.
The whole page tag format.
For example see this link:
Format the content

Shortcut in visual studio to format the whole document is Ctrl + E, D

I just use built-in Visual Studio formatting command: Ctrl+A, Alt+F8

Ctrl+E+D in Visual Studio Express 2013.

Related

Find method in current file/class in VS2015/C#

I can use the Ctrl+, shortcut to search for methods but will search among the entire project:
This lists all the classes in all files that have this method, and I want to search only in the current file, similar to Alt+M in VAssistX. Is there a shortcut for that?
I found Is there an easy way to jump right to a method within a file?, but it's for VS2012, and they only suggest Ctrl+F or Ctrl+,.
Note: I'm looking for true navigation, not Ctrl+F, and only within the current file, unlike Ctrl+,.
To expand on the answer by Matt Schley:
Ctrl + F2 -> Tab -> then start typing and it'll sift through the functions in the file.
I know you were probably looking for something else, but this is as good as it gets for what's built into Visual Studio. Maybe there's extensions available.
EDIT
This is a mapping for C#. The command name is Window.MovetoNavigation
For C++, it's default is Ctrl + F8
Not sure if this is what you're looking for, but there is a dropdown menu right above the code editor window that lists all methods and properties in the current file.
Try Ctrl + F2 to active the navigation bar, then tab over twice and you can scroll through the dropdown.
For VS2019 you can use Alt + \ for object search.
From https://learn.microsoft.com/en-us/visualstudio/ide/go-to?view=vs-2019, it says Ctrl+1, Ctrl+M for Go to the specified member. You can add your own combination to this command by going to Tools -> Options -> Keyboard and choosing Edit.GoToMember. For me it works just perfect.

Visual Studio 2013 - is there a way to re-structure the code?

I've written some messy laid out code, is there a way in VS2013 to re-structure it with the click of a button?
In general the keystroke is CTRL + E, D. However, if you're in an Express version I believe it's CTRL + K, D. But bear in mind this can really determine on how your environment is setup.
It depends on the file type, but Edit -> Advanced -> Format Document often knocks C# and VB.NET files into much better shape. Keyboard shortcut is (usually) Ctrl+E, D.
Resharper, a popular (but not free) Visual Studio plugin, offers a ton of interesting code formatting features as well, whereby you can define all the rules by which code "should" be laid out, then you run one command and it'll clean everything up. You can even save those settings in a configuration file inside the project, so that your whole team can share it.
Ctrl + K + D (Entire document)
Ctrl + K + F (Selection only)

Visual studio autocomplete to find a file?

In the Visual Studio, do we have a tool to find a file based on file name insdie a project, like typing a few letters of beginging of a file, it will autocomplete to show all files starting with that letters. In the Java Eclipse, we can use Ctrl+Shift+R , do we have similar in the VS ?
Thanks
Yes, there is something like that.
You can use the Find text box you use for normal searches as input for the Command Window. Then in the Command Window you have the of command to search files.
To do it:
CTRL + /to select the Find text box.
Type > of then the file name (or part of) you want to search for.
A dropdown list will show all files that match your typing (so you do not have to know the full file name as with CTRL + SHIFT + R).
If file list is pretty long you may use the normal Find in Files dialog, simply set Use to Wildcards, in Find what type * and write the search pattern in Look at these file types. Check the Display file name only option. Using the Look in field you can limit the search to current project, entire solution or whatever you need.
Try ctrl-spacebar, it's the normal shortcut for intelisense. If it doesn't work for file path and name, there is surely a plugin out there just for this.
I use VS with only resharper as a plugin and I can do this, I don't know if its resharper that does it or if its prebuilt.
EDIT: It is resharper that does it. I would recommend using it if you intent to work with VS as it greatly helps out on a lot of refactoring and shortcuts.

i can't add #region to .ashx in visual studio 2010

i create a generic handler (ashx) but i am trying to add region in my code like the following
#region MyRegionName
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
#endregion
there is no error but the problem that there is no expand and collapse.
please any advice ?
note: i am using visual studio 2010
hi i think i figure out the answer my self
in visual studio go to:
1- Tools -> option -> select Text Editor.
2- in the right pane add an extension "ashx" and choose from the drop down list which editor u use .. i select microsoft visual c#.
3- in the bottom check on "map extensionless to : the same selection above.
4- click ok and close the ashx page and reopen it.
thx every body for the answers
This is by design, see the explanation here: http://forums.asp.net/t/1162769.aspx#1928580.
The problem is, that the ashx file is not handled by the C# editor but by the ASP.NET editor.
EDIT: Hang on a minute - I've just re-read your question. An .ashx file, like an .asmx or .aspx file is a markup file, not a code file. You can't use regions in these files. You can use regions in the code behind files associated with them (e.g. the .ashx.cs files) only.
Original Answer: Generally, whenever I get these sort of unexplained odd behaviours in VS2010, I reset all the settings, which normally resolves the issue.
Try Tools->Import and Export Settings->Reset All Settings and see if that fixes your region issue.
If not, it may be related to a bad add-in or extension. Try disabling extensions/add-ins to see if that fixes your problem, alternatively try starting up in safe mode and see if the IDE behaves:
DEVENV.EXE /safemode
Hope this helps.
#region yourRegionName
//your code
#endregion

Automatically Format Document in Visual Studio?

Anyway of invoking the Edit > Advanced > Format Document" VS command automatically when switching away from a document / routinely with a timer / on entering a document?
Its really irritating Ctrl+E+D'ing everytime you want to prettify your code.
ReSharper does this every time you close a brace, press semicolon or paste some code in. It's not quite what you're asking for, but I don't think you'll notice the difference. Oh, and it rocks in so many other ways as well.
You can try this extension for Visual Studio 2013 I wrote recently. This is almost the same as the feature in Productivity power tools but also works for *.cshtml, *.xml and all formats which support the command "Format Document"
Format Document on Save

Categories