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.
>   

David Fishburn came up with a plugin to facilitate syntax-based replaces:

  SrchRplcHiGrp.vim  - Search and Replace based on a highlight group
  http://www.vim.org/script.php?script_id=848


Regards,
Chip Campbell


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

Reply via email to