[oclug] VI search and replace problem
Brian's Linux Box
b_mckee at myrealbox.com
Fri Jul 11 14:01:50 EDT 2003
On Friday, July 11, 2003, at 12:58 PM, Ross Jordan wrote:
>>
>> Hi All
>> I'm trying to clean up a text file in vim.
>> If there are two or more spaces between alpha characters, I want to
>> reduce that to one space.
>> From reading the docs I think
>> :%s/\a \+\a/\1 \3/g should work -
>> it matches what I'm trying to fix, but the \1 and \3 don't contain the
>> alpha characters I want to put back.
>> What do I use to represent the alpha characters matched in the \a's?
>> Brian
>
> The following appears to work:
> %s/\(\a\) \+\(\a\)/\1 \2/g
>
> Though, you may have to run it twice.
>
> -Ross
>
Yep - that works - even if it makes my head hurt.
Thank you.
I did see the note about using () to indicate a 'sub' pattern - but
that didn't work either.
I didn't realize I needed to 'escape' the brackets....
Brian
More information about the OCLUG
mailing list