locked
Cannot get the tab size to be different than the indent size

    Question

  • Hello,

    I have configured the text editor (options->text editor->C/C++) to the following settings:

    Indenting

      smart

    Tab

      Tab size: 8

      Indent size: 2

      Insert spaces (true/bullet set)

     

    I wanted the tab stops to occur at multiples of 8 and indentation to be 2 spaces.  The problem I am having is that when I press the tab key, instead of going to the next column that is a multiple of 8, it goes to the next multiple of 2 (the indent setting).

    Is it possible to make the next tab stop a multiple of 8 while keeping the indent size set to 2 ?  if so, what are the correct settings for that configuration ?

    Thank you for your help,

    John.

     

    Tuesday, March 15, 2011 5:42 PM

Answers

  • Hey John, I (re)implemented the tab/indent size logic in VS2010, so I can tell you exactly what they mean in VS2008/2010 :)

    The tab size is used for the width of a physical tab ('\t') in the file.  If you have a file with tabs in it or have "keep tabs" on in your options, it will be used for any amount of indent that is at least as big as a tab.

    The indent size is used for the language's indent level.

    The confusion, I think, is that the tab key inserts one level of indentation, not a physical tab, even when "keep tabs" is on.

    In the case of indent size 2 and tab size 8, if you put the caret at column 0 and press tab a couple of times, this is what will happen:

    Press TAB first time - inserts 2 spaces
    Press TAB second time - inserts 2 spaces (total of 4 spaces)
    Press TAB third time - inserts 2 spaces (total of 6 spaces)
    Press TAB fourth time - replaces all existing spaces with a \t (total of just a \t, which is 8 spaces wide when rendered)

    So it's not ignoring the TAB field, it just has a different(?) definition for the meaning of the TAB key.

    (You should be able to confirm this information by turning on view visible whitespace and making sure "keep tabs" is on)

    -Noah

    • Proposed as answer by Noah Richards Friday, April 01, 2011 11:10 PM
    • Marked as answer by hex440bx Saturday, April 02, 2011 5:37 AM
    Friday, April 01, 2011 11:07 PM

All replies

  • I thought you use to be able to do this. There is a setting Tools Options "Text Editor" in either the language you are using or "All Languages" look at the tabs settings for tab size and indent. However i will admit the quality of Visual Studio's editor is really going down hill with each new release.
    Tuesday, March 15, 2011 7:14 PM
  • Hello ZooDoo4U,

    I have fiddled with the settings in every way I could think of without success.  That's why I figured I'd ask here, to find out if someone had the secret that makes it work the way I'd like.

    Thank you for your suggestion,

    John.

    Tuesday, March 15, 2011 9:41 PM
  • Hi John,

     

    Thanks for your post.

    As far as I know,

    "Tab" determines the default offset length each time when pressing "Enter" and move to next line

    "Indent" means each time you press "Tab" key, the length caret moved.

    Do you like to swap them?


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 17, 2011 7:08 AM
  • Hello Victor,

    Thank you for the suggestion.  I swapped the values as you suggested but, it made both, the indent and the tab stop 8.  

    The tab stop at 8 is just fine (that's what I like) but, I would really like to have the indent at 2.

    I am starting to think, this is a bug in VS2008.  There does not seem to be a way to have the tab stops and the indent set to different values.  In other words, it looks like VS2008 completely ignores the value set in the "tab" field.

    I would love to be proven wrong :-)

    John.

     

    Thursday, March 17, 2011 11:50 AM
  • Hi John,

     

    Thanks for your feedback.

    I tried it on my VS2008 but cannot reproduce your issue, my indent and tab are just as expected,

    do you install VS2008 SP1?

    If so, I suggest to reset your settings in

    Tools->Import and Export Settings->Reset All Settings,

    and change the tab and indent size, then try again.

    If it doesn't help, be free to let me know.

     

     

    Best Regards,

    Ziwei Chen

     

     

     

     

     


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 18, 2011 2:16 AM
  • Hello Victor,

    I believe I have installed every SP and hotfix available for VS20008.  My about box reads:

    Version 9.0.30729.1 SP

    .NET Framework Version 3.1 SP1

     

    I save my settings, cleared all settings and imported my saved setting back into VS.  The tab still advances only 2 characters in spite of being set to 8 (the indent is set to 2 and that works as expected.)

    Bummer that it was not possible to reproduce the problem in your environment. 

    Any other ideas you may have are welcome and appreciated, thank you,

    John.

     

    Friday, March 18, 2011 3:31 AM
  • Hi John,

     

    I suppose you mean

    .NET Framework Version 3.5 SP1

    Anyway, you can try my scenario

    1. Create a VC++ Console Project

    2. Open ProjectName.cpp

    3. Tools->Options->Text Editor->C/C++->Tabs

    Indenting: Smart

    Tab

        Tab size: 8

        Indent size: 2

    Keep tabs

    4. Put Caret after "return 0;", press enter, default offset is 8, as I expected,

    then press "tab", move forward 2 columns, as I expected again.

    Is it behaves the same on your side?


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 18, 2011 8:30 AM
  • Hi Victor,

    Sorry for the late reply.  I reinstalled VS2008 from scratch, tried your suggestion and, still, the indent size is 2 (as it should be) but the tabs are 2 (instead of 8).

    I give up.

    It's just a minor annoyance to have to press the tab 3 times, instead of once, to reach the tab stop I want.  What the heck!

    Thank you for trying, much appreciated.

    John.

     

    Saturday, March 19, 2011 7:50 PM
  • Hey John, I (re)implemented the tab/indent size logic in VS2010, so I can tell you exactly what they mean in VS2008/2010 :)

    The tab size is used for the width of a physical tab ('\t') in the file.  If you have a file with tabs in it or have "keep tabs" on in your options, it will be used for any amount of indent that is at least as big as a tab.

    The indent size is used for the language's indent level.

    The confusion, I think, is that the tab key inserts one level of indentation, not a physical tab, even when "keep tabs" is on.

    In the case of indent size 2 and tab size 8, if you put the caret at column 0 and press tab a couple of times, this is what will happen:

    Press TAB first time - inserts 2 spaces
    Press TAB second time - inserts 2 spaces (total of 4 spaces)
    Press TAB third time - inserts 2 spaces (total of 6 spaces)
    Press TAB fourth time - replaces all existing spaces with a \t (total of just a \t, which is 8 spaces wide when rendered)

    So it's not ignoring the TAB field, it just has a different(?) definition for the meaning of the TAB key.

    (You should be able to confirm this information by turning on view visible whitespace and making sure "keep tabs" is on)

    -Noah

    • Proposed as answer by Noah Richards Friday, April 01, 2011 11:10 PM
    • Marked as answer by hex440bx Saturday, April 02, 2011 5:37 AM
    Friday, April 01, 2011 11:07 PM
  • And one other addition - you could possibly redefine the TAB key to do something else by writing a macro that listens for the tab key being pressed and inserts a tab's worth of spaces.  In VS2010 you can do something similar (an extension that listens for ECMD_TAB), which maybe someone on this forum can help you with if you'd like to do.

    -Noah

    Friday, April 01, 2011 11:09 PM
  • Hi Noah,

    Great post! that clarifies what the TAB is designed to do (which is different than what I thought it would do - act as it does in notepad and myriad other text editing apps).

    You have explained the "mystery" of the tab key.  Thank you :-)

    John.

     

    Saturday, April 02, 2011 5:33 AM
  • Hello again Noah,

    I am _almost_ drooling for a macro like the one you mentioned.   I am new to VS2008 and do not have a clue as to where to begin implementing a custom macro to change the behavior of the TAB key.

    If this is not too complicated and someone would care to post such a macro, they would have my undying gratitude :-)

    Noah, thank you again, great idea.  I will definitely look into it, see if I can figure out it.

    John.

     

    Saturday, April 02, 2011 5:37 AM
  • Thanks for your explaination Noah.
    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 04, 2011 8:51 AM