On Fri, 21 Apr 2006, Dominic Evans wrote: [snip]
the following commands replace leading spaces by tabs according to the current value of the 'tabstop' option:%s/^ \+/\=substitute(submatch(0), repeat(' ', &tabstop), "\t", 'g') :%s/^ \+/\=substitute(submatch(0), ' \{' . &tabstop . '\}', "\t", 'g') The first command only works in VIM 7.0 due to the use of the new repeat() function, but the second one should work in all versions. Regards, J??rgenThanks to both.
I'd just like to point out that J??rgen provided you a subsearch & replace alternative that follows the format: :%s/<search>/\=substitute(submatch(0), "<subsearch>", "<subreplace>", "g") This and the repeated search & replace are indispensable tools that allow for advanced editing. HTH :) -- Gerald
