On 2022-05-22, Terry Greeniaus wrote:

> If I came across as confrontational I apologize. I am comforted to
> know that I will only have to keep my .vimrc up to date rather
> than carry around other files with me as well.

> @vim-ml, I find it odd to say it's a fix when the behaviour for as
> long as I have used vim (only around 16 years, granted, and vim is
> much older) has been to not auto-indent a line following
> a trailing comment.

I know, and it's been really irritating to have to jump through
hoops to get a properly-formatted comment, especially when editing
it to add or remove text from the first line, when Vim should just
know how to do that.  And it does now.

> Also, I think you are confusing style guidelines ("Both the Linux
> kernel and Vim use multi-line end-of-line comments.") with
> actually entering code with an editor. If a comment must continue
> on the next line, then I agree that it should be indented and
> while I am entering such a comment if I hit the rightmost margin
> it would be ideal for the text editor to break the comment up into
> a new line with the automatic indent. Perhaps there is a setting
> to do that in vim; for me it just allows the line to continue past
> the width of my terminal so I need to manually break it after
> completing the over-long line.

I think that's a consequence of the behavior of the 't' and/or 'c'
flags.  I'm sorry, I can't find where that's documented.  It seems
that if the cursor is to the left of 'textwidth' when you begin
inserting text, text you add will automatically wrap.  However, if
you begin inserting to the right of 'textwidth', or you begin to the
left of 'textwidth' and your inserted text does not cross
'textwidth' then the line will not be reformatted even if the total
length exceeds 'textwidth'.

> When I do have such a comment that extends past the rightmost
> margin and I manually break the line in the middle of the comment,
> this version of vim does auto-indent it for me which is ideal. So,
> yay! I did not test an older version of vim to see if this is new
> behaviour.

If I understand you correctly, this is the new behavior, the
behavior you're not happy with.

> However, and this is the big one: if I am typing a trailing
> comment, and I have not hit the rightmost margin (perhaps I'm
> nowhere even near it) and I manually hit Enter to put in a line
> break, it should absolutely never ever ever auto-indent it.

That's what the 'r' flag is for.

    r   Automatically insert the current comment leader after
        hitting <Enter> in Insert mode.

If you don't want that, then you will have to put

    setlocal fo-=r

in an after/ftplugin/c.vim, because Vim sets it in
$VIMRUNTIME/ftplugin/c.vim.

> And yes, we can come up with an idea of how often this happens.
> Using the Linux kernel as an example, I ran the following script
> against commit ce522ba9ef7e2d9fb22a39eb3371c0c64e2a433e (which is
> where my HEAD happened to be and is not the current kernel HEAD):

[script omitted]

> The script searches for trailing double-slash comments, counts how
> many of them it finds and then counts how many times the next
> line(s) are whitespace-delimited comments at any indent. It makes
> no attempt to see if the followon line's indent actually matches
> the initial trailing comment's indent, so this is an upper bound
> on how many followon lines in the kernel could have benefited from
> an auto-indent.

[...]

> And here is the result on the Linux kernel (note that xargs splits
> up invocations so that there are no more than 5000 arguments
> passed to the script at a time which is why we get the results
> multiple times):
> 
> % find linux/ -name "*.c" | xargs python3 comment_counter.py
> Trailing comments: 718
> Followon comments: 0
> Trailing comments: 1798
> Followon comments: 68
> Trailing comments: 1025
> Followon comments: 4
> Trailing comments: 889
> Followon comments: 5
> Trailing comments: 1264
> Followon comments: 13
> Trailing comments: 1285
> Followon comments: 19
> Trailing comments: 1148
> Followon comments: 3
> % find linux/ -name "*.h" | xargs python3 comment_counter.py
> Trailing comments: 11752
> Followon comments: 166
> Trailing comments: 7451
> Followon comments: 226
> Trailing comments: 538
> Followon comments: 8
> Trailing comments: 633
> Followon comments: 1
> Trailing comments: 634
> Followon comments: 46
> 
> And finally, I tabulate the results:
> 
> Total trailing comments: 29135
> Total followon comments: 559
>     Percentage of time hitting <Enter> should auto-indent:  
> 1.9186545392140038%
> Percentage of time hitting <Enter> should not auto-indent: 98.081345460786%
> 
> I claim a >98% rate where the line following a trailing comment in
> the Linux kernel should not be indented is consistent with
> "practically nobody ever wants this behaviour". I also withdraw my
> baseless statistic that 3 people out of 15 million actually desire
> this behaviour since obviously that is completed unsubstantiated
> and not helpful to the discussion; hopefully this analysis is more
> constructive in choosing what the default behaviour should be.

Nice!

While I often allow my trailing comments to extend to the next line,
I try to keep them to one line, and I have the 'r' flag set in
'formatoptions', so I should experience this problem, but I don't.
I don't know why.  I'll pay more attention to my typing this week.

I have the 'o' flag unset, so it may be that I end one-line trailing
comments with <Esc>o rather than <Enter> and I'm just so used to it
that I don't think about it.

Do you hit <Enter> often enough when typing a block comment for
unsetting the 'r' flag to be a problem?

I think we agree that the new behavior works well when it's
wanted, and that it is sometimes wanted though more often not--the
question is how to control when it is applied.

Regards,
Gary

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220522225343.GE2386%40phoenix.

Raspunde prin e-mail lui