Hi,
I'll post a simplified version of my problem. Basically, I want to
substitute every occurrence of 'a' (the letter a, without the quotes) with
'b', but only if 'a' is not inside a string, by which I mean it is not
enclosed in double quotes.
So, for the line:
1234 a a "a" a
I'd like to get:
1234 b b "a" b
The question is, is this possible and how.
What I've tried is
let line = substitute(line, '\([^\"]\{-}\)a', "\\1b", "g")
(in Vim-script)
There are a few obvious problems with this. First off, I'm not sure whether
the \ before the " is necessary (Vim regex syntax is unfortunately sort of
idiosyncratic), but in any case, neither version works. The output I get for
the previous line is:
1234 b b "b" b
I've also tried adding ^ to the start of the regex, but then I get
1234 b a "a" a
despite the "g" flag.
Also, the above code in no way addresses the part "behind" the strings. For
that I tried something like
let line = substitute(line,
''^\(\([^"]\{-}\)\|\(.\{-}".\{-}".\{-}\)\{-}\)a', "\\1b", "g")
hoping to match anything without a quote at the start of a line or starting
with any number of strings (an even number of quotes).
This version gives me
1234 b a "a" a.
Any help is appreciated,
Ivan
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---