PRB: Visual C++ Wizards Ignore "Insert Spaces" in Tabs Option

ID: Q178995


The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.0a, 4.1, 4.2, 4.2b, 5.0, 6.0


SYMPTOMS

AppWizard and ClassWizard always generate code indented with tabs, regardless of the "Insert Spaces" setting.


RESOLUTION

Visual C++ 5.0 and 6.0

To remove all undesired tab characters from text displayed in Visual C++ Developer Studio, use the Untabify feature. To "untabify" a set of lines:
  1. Select the line(s) containing the undesired tab characters. To select the entire document, click Select All on the Edit menu.


  2. Click Advanced on the Edit menu, then click Untabify Selection. Spaces replace tab characters. The selected text's visible formatting does not change. All tab characters are correctly replaced by an appropriate number of spaces.


Visual C++ 4.x

To remove undesired tab characters from text displayed in Visual C++ versions earlier than 5.0, use the Replace feature. Follow these steps:
  1. Determine your tab expansion setting. Click Options on the Tools menu, then click Tabs on the dialog box. Note the setting labeled "Tab size".


  2. Select the line(s) containing the undesired tab characters. To remove tabs from the entire document, see step 4.


  3. Click Replace on the Edit menu. In the "Find what" field, type a number of spaces corresponding to the "Tab size" setting. In the "Replace with" field, type in the same number of spaces.


  4. In the "Replace in" section, select either "Selection" or "Whole file." Click "OK.[ASCII 148] Leading and full-width tabs are now replaced with spaces.


  5. To remove tabs whose effective widths do not correspond to the "Tab size" setting (tabs between text), repeat replacing as in steps 3 and 4 but with one less space each time in the "Find what" and "Replace with" fields. After replacing all single spaces with single spaces, there will be no remaining tabs in the selection.



STATUS

This behavior is by design.


MORE INFORMATION

Visual C++ Developer Studio offers options to control how the editor processes tab keystrokes. If the "Insert Spaces" option is selected for the current file type, the editor embeds spaces instead of tab characters into source code whenever the user presses the TAB key.

Some earlier text editors and utility programs automatically expand tabs to a fixed setting, which the user cannot configure (usually eight characters). The text formatting that they display will not properly represent code written with tab expansion set to a different value (four is the default in Developer Studio). For this and other reasons, some users may prefer to have their code formatted with spaces only.

However, AppWizard and ClassWizard always generate code indented with tabs, regardless of the "Insert Spaces" setting. This behavior may annoy those users who prefer spaces.

Steps to Reproduce Behavior

  1. Start Visual C++ 5.0.


  2. Click Options on the Tools menu and choose the Tabs section.


  3. Select "Insert Spaces". Save the setting by clicking OK.


  4. Create a new project with any of the AppWizards, and open one or more of its files.


  5. Click Advanced on the Edit menu, then click View Whitespace (not available in VC++ 4.x). The caret symbol (^) will appear where tab characters exist. Verify that indented lines contain tab characters.


Additional query words:

Keywords : kbwizard kbCodeGen kbide kbMFC kbVC kbVC400 kbVC410 kbVC420 kbVC500 kbVC600 kbGrpDSTools
Version : Winnt:4.0,4.0a,4.1,4.2,4.2b,5.0,6.0
Platform : winnt
Issue type : kbprb


Last Reviewed: July 21, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.