Indentation shortcuts in Visual Studio

C#Visual Studio-2010DelphiIndentation

C# Problem Overview


I'm new to Visual Studio 2010 and C#. How can I indent the selected text to left/right by using shortcuts?

enter image description here

In the Delphi IDE the equivalents are Ctrl+Shift+I and Ctrl+Shift+U

C# Solutions


Solution 1 - C#

Tab and Shift+Tab will do that.

Another cool trick is holding down ALT when you select text, it will allow you to make a square selection. Starting with VS2010, you can start typing and it will replace the contents of your square selection with what you type. Absolutely awesome for changing a bunch of lines at once.

Solution 2 - C#

> Ctrl-K, Ctrl-D > > Will just prettify the entire document. Saves a lot of messing about, > compared to delphi.

Make sure to remove all indents by first selecting everything with Ctrl+A then press Shift+Tab repeatedly until everything is aligned to the left. After you do that Ctrl+K, Ctrl+D will work the way you want them to.

You could also do the same but only to a selection of code by highlighting the block of code you want to realign, aligning it to the left side (Shift+Tab) and then after making sure you've selected the code you want to realign press Ctrl+K, Ctrl+F or just right click the highlighted code and select "Format Selection".

Solution 3 - C#

If you would like nicely auto-formatted code. Try CTRL + A + K + F. While holding down CTRL hit a, then k, then f.

Solution 4 - C#

Tab to tab right, shift-tab to tab left.

Solution 5 - C#

Visual studio’s smart indenting does automatically indenting, but we can select a block or all the code for indentation.

  1. Select all the code: Ctrl+a

  2. Use either of the two ways to indentation the code:

  • Shift+Tab,

  • Ctrl+k+f.

Solution 6 - C#

You can just use Tab and Shift+Tab

Solution 7 - C#

Just hit Tab to push it over or on the menu bar Edit --> Advanced --> Format Selection and that will auto indent, the keyboard shortcut is also shown in the menu.

Solution 8 - C#

If the move-left and move-right shortcuts do not appear on your screen, click at the rightmost position of your toolbar at the top. You should get "Add or Remove Buttons." Add the buttons "decrease line indent" and "increase line indent"

Solution 9 - C#

Firstly select the text you want to edit(indent), then press Tab to see the snippet move towards the right.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRBAView Question on Stackoverflow
Solution 1 - C#Mike ChristensenView Answer on Stackoverflow
Solution 2 - C#Tony HopkinsonView Answer on Stackoverflow
Solution 3 - C#MausimoView Answer on Stackoverflow
Solution 4 - C#Giovanni GalboView Answer on Stackoverflow
Solution 5 - C#JorgesysView Answer on Stackoverflow
Solution 6 - C#Bassam MehanniView Answer on Stackoverflow
Solution 7 - C#SchreinboView Answer on Stackoverflow
Solution 8 - C#user3029478View Answer on Stackoverflow
Solution 9 - C#Preet ShahView Answer on Stackoverflow