I have something like the following text
( parens ) ( 1 + growth ) (1+growth) (1 +growth) ( parens )
and I'd like replace every instance of ( 1 + growth )
, regardless of whitespace, with say, growthFun
The nongreedy search command
:g/(.\{-}1.\{-}+.\{-}growth.\{-})/s//growthFun/gc
almost works, i.e., it locates the second and third instances, but the first time around it grabs ( parens ) ( 1 + growth )
This is puzzling since it does not do the same thing at the end of the line, i.e., it does not grab (1 +growth) ( parens )
the third time around. Could somebody please explain why the difference, and then how to avoid the first incorrect grab?
A closely related question is: the nongreedy construction .\{-}
must be the most horrible, unnatural things the vi
inventors every invented. Is there a way to alias it in .vimrc
so that, for example, typing
:g/( ;ng 1 ;ng etc )
would expand to
:g/( .\{-} 1 .\{-} etc )
Thanks for any advice!
.\{-}
with\s\{-}
or[^()]
, the command looks like it works according to your requirement. Would that be acceptable (look just for a space(s) or non-parenthesis in lieu of non-newline characters?