3

I've the following sample INI file:

Foo=1
Bar=1
Baz=1
Qux=1

and my goal is to set all options to 0 except Foo.

To disable one selected line, I know that I can run:

%s/Foo=\zs.*$/0/

Test command in shell:

$ ex +"%s/Foo=\zs.*$/0/p" -scwq file.ini
Foo=0

How can I negate substitution pattern, for example disabling every other option apart of Foo?

I'm also open for suggestions to use different commands instead to achieve the same result.

  • 5
    Does it have to be done with a substitute command? If you're OK using a different command, you could use global, e.g. :g!/Foo/norm f=lC0 – DJMcMayhem Feb 5 '17 at 0:38
  • @DJMcMayhem Yes, it can be different command as well. If you put it into the answer, it would be great. – kenorb Feb 5 '17 at 1:54
5

You can use :v, e.g. something like this should work: :v/^Foo/s/.*=\zs\d$/0/g

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.