Comment auto formatting joins non-comment lines

9 views
Skip to first unread message

Adam Levy

unread,
Oct 18, 2022, 2:53:54 AM10/18/22
to vim_use
I like the autoformatting of comments when I'm writing them, however it's unusable because subsequent non-comment lines are always joined with the comment block.

Use of fo+=w helps a little bit, but if I accidentally leave Insert mode when there is a trailing space on the last line of my comment, it will join it with the next line regardless of whether the next line is a comment or not. This is really annoying and feels like incorrect behavior. It seems to me that autoformatting should never change or join a non-comment line into a comment line.

For example, I might have code like the following:

// FooBar does things.
func FooBar() {
    return
}

If my formatoptions are
formatoptions=crqwn1ja

Then when I go to edit the comment, if I happen to leave a space at the end accidentally, then it is autoformatted into this:

// FooBar does things. func FooBar() {
    return
}

If w isn't set then the space doesn't matter and it will always get formatted into that immediately.

Is this correct behavior? Is there a way to get vim to auto format comments but never join a non-comment line? Or should I just resign and not use the fo+=a option for code?

Bram Moolenaar

unread,
Oct 18, 2022, 8:12:12 AM10/18/22
to vim...@googlegroups.com, Adam Levy
This looks like a bug, since you have the "c" flag, which together with
"a" should mean only comments are auto-formatted.

--
<Beeth> Girls are like internet domain names,
the ones I like are already taken.
<honx> Well, you can stil get one from a strange country :-P

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages