I'd do something like this:
if &fo =~ 'r' && &fo =~ 'o'
set fo-= fo-=r
else
set fo+=ro
endif
That is, if 'formatoptions' contains both 'o' and 'r', remove those
flags, otherwise add those flags.
see...
:help expr-option
:help :set+=
:help :set-=
~Matt
Matt's solution is good, but I think he missed a "o" in his
transcription of the "-=" bits:
set fo-=o fo-=r
^
The whole shebang should be mappable if needed.
-tim
Good catch, it was a typo. :)
Thanks Tim.
~Matt
> Matt Wozniski wrote:
>> if &fo =~ 'r' && &fo =~ 'o'
>> set fo-= fo-=r
>> else
>> set fo+=ro
>> endif
>
> Matt's solution is good, but I think he missed a "o" in his
> transcription of the "-=" bits:
>
> set fo-=o fo-=r
> ^
Also, sometimes it may be better to use "setlocal" instead of "set". The
"set" command keeps changing the default value of 'fo'.