Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a format code shortcut for Visual Studio?

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?

like image 970
Soumya Avatar asked Feb 09 '11 06:02

Soumya


People also ask

How do I beautify the code in Visual Studio?

To do this, go to File->Preferences->Settings: Under Text Editor, select Format On Save. Now when saving a file, it will be beautified. THANKS FOR READING.

How do I add formatting in Visual Studio?

Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.

How do you arrange code in VS Code?

The code formatting is available in Visual Studio Code through the following shortcuts: On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.

How do I change the format in Visual Studio?

To access this options page, choose Tools > Options from the menu bar. In the Options dialog box, choose Text Editor > C# > Code Style > Formatting.


2 Answers

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 menu ToolsOptionsEnvironmentKeyboard (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 menu EditAdvanced 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!)

like image 161
Jason Williams Avatar answered Sep 20 '22 18:09

Jason Williams


Ctrl + K + D (Entire document)

Ctrl + K + F (Selection only)

like image 31
santosh singh Avatar answered Sep 18 '22 18:09

santosh singh