IDM PowerTips

Tabs to Spaces – Ignore tabs and spaces in string and comments

Ever had to convert the tab characters to spaces, but wanted to leave the tabs in strings and comments untouched? In previous versions, the convert tabs to spaces feature didn’t distinguish between tabs as whitespace/formatting vs. tabs in string/comments. Those days are gone… UltraEdit/UEStudio can be optionally configured to convert the whitespace/formatting tabs but leave the tabs in strings/comments untouched.

Ignore spaces and tabs inside comments and string

By default, the convert tabs to spaces (or spaces to tabs) feature will convert all tabs and/or spaces; however, you can optionally configure UltraEdit/UEStudio to ignore the tab/space charaters in comments and strings.

For the purposes of this power tip, we are using a tab/space value of 4. We have also enabled the View Spaces/Tabs in the View menu. The tabs are represented by the chevron (»), the spaces are represented by the dot (•).

As demonstrated in the following screenshot, the sample code includes tabs as “formatting”. The code also includes tabs inside strings. The output for the PHP sample file is a type of CSV file – delimited with tabs – so it is important that the tabs inside the string characters remain untouched by the conversion.

Now, to enable support for the “ignore” feature, go to Advanced : Configuration : Editor Display : Formatting and check (enable) the setting for “Do not convert spaces and tabs inside comments and strings”. This will tell UltraEdit/UEStudio to convert the whitespace/formatting tabs (or spaces) but ignore the tabs (or spaces) in comments and strings.

After setting the “ignore” option, click on the “Tabs to Spaces” option in the Format menu.

You should see that the formatting tabs are converted to spaces but the tabs inside the strings remain untouched.