Toggle formatoption flags? [sj]

5 views
Skip to first unread message

smu johnson

unread,
Dec 1, 2008, 1:10:11 PM12/1/08
to v...@vim.org
Dear faithful vim users,

I was wondering how some of guy friendly folks have gone about toggling the fo / formatoptions flags.  I haven't been able to find anything in the man page because it lacks common applications for the advice it gives.

I'm basically trying to bind a key to toggle the auto-comment ability found in it.  Any thoughts?  Thanks in advance.

--
smu johnson <smujo...@gmail.com>

Matt Wozniski

unread,
Dec 1, 2008, 3:15:00 PM12/1/08
to vim...@googlegroups.com

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

Tim Chase

unread,
Dec 1, 2008, 3:19:55 PM12/1/08
to vim...@googlegroups.com
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
^

The whole shebang should be mappable if needed.

-tim

Matt Wozniski

unread,
Dec 1, 2008, 3:33:37 PM12/1/08
to vim...@googlegroups.com
On Mon, Dec 1, 2008 at 3:19 PM, Tim Chase wrote:
> Matt's solution is good, but I think he missed a "o" in his
> transcription of the "-=" bits:
>
> set fo-=o fo-=r
> ^

Good catch, it was a typo. :)

Thanks Tim.

~Matt

smu johnson

unread,
Dec 1, 2008, 6:23:06 PM12/1/08
to vim...@googlegroups.com
You guys... are good guys.  Thanks a ton!

2008/12/1 Matt Wozniski <m...@drexel.edu>



--
smu johnson <smujo...@gmail.com>

Teemu Likonen

unread,
Dec 2, 2008, 2:26:15 AM12/2/08
to vim...@googlegroups.com
Tim Chase (2008-12-01 14:19 -0600) wrote:

> 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'.

Reply all
Reply to author
Forward
0 new messages