Regular expression – how to replace the intraline tag with spaces, keep alignment?

I like to use spaces to indent rather than labels; in sed or vim, it is easy to replace tabs at the beginning of the line:

s/^I/ /g

But if there are tabs in a line (assuming the space is the width of the tab characters):

'foo'^I ^I =>'bar',
'bazzle'^I =>'qux',

Each tab does not correspond to the set number of maintaining alignment Spaces. Anyone have a cunning idea, how to replace these tabs with spaces while maintaining proper alignment?

In Vim:

 :retab

Or, if you have a tag after the space:

:retab!

I like to use spaces to indent rather than labels; in sed or vim, it is easy to replace tabs at the beginning of the line:

s/^I/ /g

But if there are tabs in a line (assuming the space is the width of the tab characters):

'foo'^I ^I => 'bar',
'bazzle'^I =>'qux',

Each tab does not correspond to a set number of spaces to maintain alignment. Anyone has a cunning Idea, how to replace these tabs with spaces while maintaining correct alignment?

In Vim:

:retab

Or, if You have a tag after the space:

:retab!

Leave a Comment

Your email address will not be published.