Unexpected results from applying gqj to C line comment

8 views
Skip to first unread message

Gary Johnson

unread,
Dec 28, 2021, 7:15:50 PM12/28/21
to vim...@googlegroups.com
The formatting command gqj exhibits unexpected behavior when
executed on a C line comment after a statement. The reformatting is
applied only to the first line of the comment and not to the
following line.

Formatting of C line comments after statements was added with Patch
8.2.3787. It generally works very well. I've recently observed the
behavior described here. It seems like a bug.

Steps to reproduce

1. Start vim as:

$ vim -N -u NONE -i NONE -c 'set cin tw=40'

The 'tw' setting is just for convenience.

2. Enter these lines into the buffer:

#if 0 // This is a long end of
// line comment that
// wraps.

3. Replace the "a" with "another":

#if 0 // This is another long end of
// line comment that
// wraps.

4. With the cursor still on the first line, attempt to reformat the
first two lines with

gqj

The comment now appears like this:

#if 0 // This is another long
// end of
// line comment that
// wraps.

and the cursor is at the start of the third line.

Expected behavior

I expected the comment to appear like this:

#if 0 // This is another long
// end of line comment
// that
// wraps.

That is, with the first two lines of the comment formatted
together and a third line created for what was the last word of
the second line. That is the result obtained when "#if 0" is
not present.

Operating system

Ubuntu 20.03.3 LTS
Xterm 370

Version of Vim

8.2.3930

Regards,
Gary

Bram Moolenaar

unread,
Dec 29, 2021, 9:10:11 AM12/29/21
to vim...@googlegroups.com, Gary Johnson
I can reproduce it. Looks like the first line is split, but not joined
with the next line.

--
hundred-and-one symptoms of being an internet addict:
136. You decide to stay in a low-paying job teaching just for the
free Internet access.

/// 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