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. 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. --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
