On 17/07/09 15:33, Ben Fritz wrote:
>
> StarWing asked this, probably intended as a rhetorical question, in
> vim_dev:
>
> http://groups.google.com/group/vim_dev/browse_thread/thread/e6caa2bb4099306b/ec1efe41296398a7
>
>> can you write a pattern to replaced foo to bar in code, but not in
>> string and comment? that's useful, but Vim pattern doesn't support
>> that :-( maybe makes user can get current syntax state easily is
>> better.
>
> I came up with this:
>
> %s/foo/\=(match(map(synstack(line('.'),col('.')), 'synIDattr(v:val,
> "name")'), '\([Cc]omment\)\|\([sS]tring\)')>= 0 ? "foo" : "bar")/g
>
> It's cheating (I wouldn't exactly call that a "pattern") but it
> works...at least for me.
[...]

IIUC, technically the "pattern" here is just /foo/ -- or, rather, the 
string 'foo' but there are many places where patterns are bounded by 
slashes.

Everything between /foo/ and /g is the replacement string, or in this 
case, '\=' plus the replace-expression.

I would call the whole line a substitute, or to be more precise, 'a 
":substitute" command'. Calling it a "pattern" is in this case an abuse 
of language, which may perhaps be condoned in informal text since the 
context is clear.

(And, yes, I'm a retired teacher, and I can be quite a pedant when it 
suits me.)


Best regards,
Tony.
-- 
All of the true things I am about to tell you are shameless lies.
                -- The Book of Bokonon / Kurt Vonnegut Jr.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to