How do you use Tab Size and Indent Size?

The Editor team wants to build the best product possible, and we need your help!  This week, the team would like to ask for direct feedback on how you use tab size and indent size.  Tab size is the amount of space each tab occupies, while indent size is the amount of space automatically inserted for each level of indentation at the left of a line.  Both options can be found in Visual Studio under ToolsàOptionsàText Editorà[Your Language]àTabs, and by default both are set to 4 spaces.


For example, if you turn on visible whitespace with tab size = indent size = 4, your code would look like this:

Tab Size = 4, Indent Size = 4.  Click for best quality.


But with tab size = 4 and indent size = 8, the same code would look like this: 

Tab Size = 4, Indent Size = 8.  Click for best quality. 


One of the many advantages of the new editor is that unlike previous versions, Visual Studio 2010 can support multiple font faces and multiple font heights.  With this new capability, there are more choices than ever for how to format your code, which led the Editor team to some interesting design questions.  We want to make sure we design features that look great and feel natural in your most important use cases.  With that in mind, we'd like to know:


·         What are your preferred tab & indent size settings?  Why do you choose that particular configuration?

·         Do you keep tabs or insert spaces?

·         Is there a case where you use different tab & indent sizes?  If so, please tell us the scenario.

Feel free to leave a comment or use the Email link.  The more we understand about how you use Visual Studio, the more we can improve it.  And stay tuned for the next post, when we’ll give you a sneak peek and a chance to tell us what you think about an updated UI for code outlining.

Brittany Behrens
Program Manager, VS Platform Team

Comments (8)

  1. Chad says:

    At the company I work for (300+ VS developers) we use a default of Tab Size: 4, Indent Size: 4.

    That is also what I use, and most of the developers keep.

    We also prefer the "Keep Tabs" obtion instead of "Insert Spaces", less moving of the cursor when editing.

  2. wekempf says:

    Tab and indent size are the same (can’t imagine why you’d ever want different sizes). I prefer 3, but use 4 as well, depending on the project and preferences of the team.  We always replace tabs with spaces, which is the only way to ensure consistency with others.  Moving of the cursor when editing isn’t really relevant, when you use Ctrl+Arrow.

  3. Daniel Smith says:

    This topic is opening a can of worms isn’t it?  The age old debate between tabs and spaces is always heated, and in the end it’s easier just to give folk maximum felxibility to work the way they feel comfortable with.

    I personally always use the default of 4 for both settings.  It’s a happy medium – any smaller and code looks too crushed, and any larger is just a waste of space.

    I also leave the default "Insert Spaces" option on.  It’s a lot less painful than having mixtures of tabs and spaces.  Plus it’s easier to get things lined up – especially rows of end of line comments – and for them to stay lined up no matter what the tab settings are on individual machines.

    Since the default settings in VS are already excellent, it’s much more likely that devs simply leave the settings as they are and adopt them as standard, which is much better than having everyone in the team bickering over their preferred style at the start of every new project!

  4. VSEditor says:

    Daniel – You’re right that the tabs vs. spaces debate can get pretty heated; I assure you we won’t be changing that option any time soon 🙂  Tabs vs. spaces is helpful information to know when considering developers’ preferences for tab/indent size, though, which is why I ask.

    Thanks for the feedback so far.  Keep it coming!

  5. brettwo says:

    I tend to just leave the default settings as they are, as I find them perfectly suitable to my needs  (I think it’s 4/4, which is what I like anyway).  I generally prefer inserting spaces for tabs, since it will guarantee everything is lined up how I want it no matter what an indivdual editor’s settings are.  Most important to me, though, is that it’s _always_ either tabs or spaces, so that, even if the settings are different on another machine and things aren’t indented where I want them, it’s at least consistent within the file.  Having some tabs and some spaces leads to very messy looking code if you don’t have the right tab settings.

    Speaking of which, it would be really cool if there were a Formatting policy in TFS (like existing Security or Code Analysis policies) so that this could be enforced on checkin.  That way, I could guarantee that all code in my project, no matter who wrote it, will be formatted consistently.  Is this something you guys would consider for a future version?

  6. Will says:

    I always use the same setting for tab/indent sizes (at 4).  My team typically uses "Insert Spaces", but this is not consistent across all files in my product.

    It would be nice if there were a setting in Visual Studio to "mimic file" so that the editor would detect whether all of the indents are tabs or spaces and use whatever the file default was.  If the file wasn’t consistent, it could default to whatever the other setting is or whatever is first.

    It would also be nice if files could be saved in ASCII for files created in Visual Studio.

  7. says:

    4/4 inserting spaces. That’s clearly the way Kosmic Muffin intended editors to behave!

  8. Ooh says:

    Using 4/4 as I think it’s the optimal value:

    – I can’t stand odd values

    – 2 does not highlight the indentation enough so for me it’s hard to follow the control flow

    – 6 and above makes code feel too distant and the caret jumps around too much

    Personally I prefer tabs over spaces because it’s much easier to align code lines. With spaces it happens very easily that you delete one or two spaces less or more than needed which results in strange code layout (which I don’t recognize in the first moment). After this happened to me several times I switched back to "keep tabs" because it’s the typical "all or nothing" approach.

Skip to main content