Format code shortcut for Visual Studio?

2019-01-09 21:35发布

问题:

In eclipse there is a shortcut Ctrl+Shift+F that re-indents code and fixes comments and blank lines. Is there an equivalent for Visual Studio 2010?

回答1:

Visual Studio WITH C# KEY BINDINGS

To answer the specific question, in C# you are likely to be using the C# keyboard mapping scheme, which will use these hotkeys by default:

Ctrl+E, Ctrl+D to format the entire document.

Ctrl+E, Ctrl+F to format the selection.

You can change these in Tools > Options > Environment -> Keyboard (either by selecting a different "keyboard mapping scheme", or binding individual keys to the commands "Edit.FormatDocument" and "Edit.FormatSelection").

If you have not chosen to use the C# keyboard mapping scheme, then you may find the key shortcuts are different. For example, if you are not using the C# bindings, the keys are likely to be:

Ctrl + K + D (Entire document)

Ctrl + K + F (Selection only)

To find out which key bindings apply in YOUR copy of Visual Studio, look in the Edit > Advanced menu - the keys are displayed to the right of the menu items, so it's easy to discover what they are on your system.


(Please do not edit this answer to change the key bindings above to what your system has!)



回答2:

Ctrl + K + D (Entire document)

Ctrl + K + F (Selection only)



回答3:

try Ctrl + K + D ("don't leave Ctrl in between")



回答4:

Yes, you can use the two-chord hotkey (Ctrl+K, Ctrl+F if you're using the General profile) to format your selection.

Other formatting options are under Edit » Advanced, and like all VS commands, you can set your own hotkey via Tools » Options » Environment » Keyboard (the format selection command is called Edit.FormatSelection).

Formatting doesn't do anything with blank lines, but it will indent your code according to some rules that are usually slightly off from what you probably want.



回答5:

resharper - Ctrl + Alt + F

VS 2010 - Ctrl + K, Ctrl + D



回答6:

To align the text in proper format =

Ctrl + K + D for front end pages like .aspx or .cshtml

Ctrl + K + F for .cs page

but note that press all buttons in sequence accordingly..



回答7:

Format the entire document: ctrl + k + d



回答8:

Select all document and press Ctrl + E + D



回答9:

Format for selection:

ctrl + k + f

format for entire document:

ctrl + k + d