On Jul 17, 9:33 pm, Ben Fritz <[email protected]> wrote:
> StarWing asked this, probably intended as a rhetorical question, in
> vim_dev:
>
> http://groups.google.com/group/vim_dev/browse_thread/thread/e6caa2bb4...
>
> > 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.
>
> However, I'm a little curious about the use of line('.') and col('.')
> within a sub-replace-expression. It certainly seems to be executing as
> if the cursor is at the position of the match, but is this something I
> can depend on always being the case? I can't find documentation of
> this fact anywhere!
>
> I had to learn about the "map()" function for this to work...Vim never
> ceases to amaze.
thank you! but you feel comfortlessness isn't it? maybe we can do
something change it. and submatch(), I don't like it...
for submatch, I just want to write a patch to support v:1, v:2, etc. :
if str =~ '\(foo\)\(bar\)'
echo v:1 v:2 " should echo foo bar.
endif
that can work in anytime you used pattern. but I found to implement is
not easy...
\= is a good thing. BUT it can't recursion :-(
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---