On Fri, 21 Apr 2006, Dominic Evans wrote:
I like to have leading spaces as tabs, but all spaces after any
non-whitespace character has occurred to be regular spaces.
Unfortunately :retab! performs the spaces->tab substitution throughout the file.
In the past I have got around this by using the following replace
instead (where ^I = tab)
:%s/^\([^I]*\) /\1^I/g
This replaces sequences of 4 spaces immediately at the start of the
line, or immediately after a number of tabs at the start of the line.
Due to its nature I have to run this several times to achieve the
desired result.
Therefore I have two questions:
a) could we have a variant of :retab that performs this function - I
believe it is a fairly common way of having source code
There's a general dislike for tabs because it is editor-dependent. I
only seem to find use for them in Makefiles.
b) is there a way of making the substitution automatically re-run
itself until no more possibilities exist?
Yes, a repeated search & replace follows the format:
:g/<search>/wh getline(".")=~@/|s//<replace>/|endw
Here's a suggestion to what you may want:
:g/^\t*\zs[ ]\{1,4}/wh getline(".")=~@/|s//\t/|endw
where 4 is what you set 'tabstop' to. See ":help 'tabstop'".
HTH :)
--
Gerald