Wednesday, July 28, 2010

Re: Replace except enclosed by delimiters (")

On 07/28/10 11:50, Christian Brabandt wrote:
> On Mi, 28 Jul 2010, Tim Chase wrote:
>>> FOO, FOO, fooO, "foOO"
>>>
>>> I want it to become
>>>
>>> foo, foo, fooo, "foOO"
>>
>> You can use the following:
>>
>> :%s/\%(^\%([^"]\+\|"[^"]*"\)*\)\@<=[^"]\+/\L&/g
>
> Nice. I tried, but didn't find a solution. However, this solution is
> really slow, when I tried it on a buffer with only the sample data.

Yeah, the slowness is an unfortunate side effect because for
every match, it has to look back at the preceding bit of the line
to ensure there's not an odd number of double-quotes. I didn't
find it notably slow in practice, but one might be able to put in
a few fast-checks something like

:%s/\%(^\%([^"]\+\|"[^"]*"\)*\)\@<=\<[^"]\+/\L&/g

(adding the "\<") so that fewer matches can be found that require
back-tracking.

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: