Provided I correctly understand the task at hand :-), the Entab command (Text -> Entab) set to a tab width of 4 spaces should do what you need.

Regards,

 Patrick Woolsey
==
Bare Bones Software, Inc.             <http://www.barebones.com/>



On 2/25/16 at 3:05 PM, [email protected] (Brian Porter) wrote:

I'm trying to find a trick for using the grep-enabled Find/Replace BBEdit to convert files that use spaces for indentation to using tabs. Here's an example input text snippet:

1. Item
a. sub-item
i. third level
ii. another third level
2. Second Top Level


What I'd like to do is replace all sets-of-4-spaces at the beginning of the line with a single tab (per each 4-space-set), but it seems like this would require being able to count the *number *of matches and use that in the back reference somehow

For example, the following search and replace patterns can be used to replace the *first *set of spaces with a tab, but this pattern must be applied repeatedly for every "level" of indent being used in the file:

*Find:*
^(\t*)(\ \ \ \ )

*Replace:*
\1\t


Ideally I want something like this:

*Find:*
^((\ \ \ \ )+)

*Replace:*
\t{countOf(\2 in \1)} # Yes it's wildly invalid; use your imagination. :-P


I'm unaware of any mechanism in grep/regex that would allow for this. Am I correct in thinking it's impossible? Is there an alternative approach, perhaps via Apple/shell script that could get the job done that I'm not considering?

Thanks,
Brian


--
This is the BBEdit Talk public discussion group. If you have a feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--- You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to