[c#] 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?

The answer is


To align the text in the proper format -

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

  • Ctrl + K + F for a .cs page

But observe to press all buttons in sequence...


Format the entire document:

Ctrl + K + D


ReSharper - Ctrl + Alt + F

Visual Studio 2010 - Ctrl + K, Ctrl + D


Right click on the code, and you have "Format Document". In my case it is Ctrl+Shift+I

enter image description here


Select all text in the document and press Ctrl + E + D.


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 menu EditAdvanced, and like all Visual Studio commands, you can set your own hotkey via menu ToolsOptionsEnvironmentKeyboard (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.


Change these shortcuts in Visual Studio

Tools ? Options ? Environment ? Keyboard

and then change the command

"Edit.FormatDocument" or "Edit.FormatSelection"

assign the same shortcut alt + shift +f as in visual studio code in order to not remember another one and confuse between each other.


Ctrl + K + D (Entire document)

Ctrl + K + F (Selection only)


Try Ctrl + K + D (don't lift the Ctrl key in between).


Simply


For Visual Studio Code Use ALt + Shift + F

for Visual Studio IDE Press Ctrl + K followed by Ctrl + D


It will beautifully format the entier file.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to visual-studio-2010

variable is not declared it may be inaccessible due to its protection level SSIS Excel Connection Manager failed to Connect to the Source This project references NuGet package(s) that are missing on this computer Gridview get Checkbox.Checked value error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj What is the difference between Visual Studio Express 2013 for Windows and Visual Studio Express 2013 for Windows Desktop? Attach (open) mdf file database with SQL Server Management Studio What is and how to fix System.TypeInitializationException error? Could not load file or assembly "Oracle.DataAccess" or one of its dependencies IIS error, Unable to start debugging on the webserver

Examples related to visual-studio

VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio? How to download Visual Studio Community Edition 2015 (not 2017) Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio Code pylint: Unable to import 'protorpc' Open the terminal in visual studio? Is Visual Studio Community a 30 day trial? How can I run NUnit tests in Visual Studio 2017? Visual Studio 2017: Display method references

Examples related to visual-studio-2012

How to actually search all files in Visual Studio Tests not running in Test Explorer How to use _CRT_SECURE_NO_WARNINGS Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0 How can I resolve the error: "The command [...] exited with code 1"? Could not load file or assembly Exception from HRESULT: 0x80131040 MSVCP120d.dll missing How can I change IIS Express port for a site The program can't start because MSVCR110.dll is missing from your computer Controlling execution order of unit tests in Visual Studio

Examples related to visual-studio-2013

Microsoft Advertising SDK doesn't deliverer ads Visual Studio 2013 error MS8020 Build tools v140 cannot be found Visual Studio 2013 Install Fails: Program Compatibility Mode is on (Windows 10) 'cannot find or open the pdb file' Visual Studio C++ 2013 Force uninstall of Visual Studio How to enable C# 6.0 feature in Visual Studio 2013? Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE] even if app appears to not be installed Process with an ID #### is not running in visual studio professional 2013 update 3 Error C1083: Cannot open include file: 'stdafx.h' The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)"