Using the following settings
set textwidth=40
set fo? -> formatoptions=croql)
set comments? -> comments=sO:* -,mO:* ,exO:*/,s1:/*,mb:*,ex:*/,://
set cindent
set cinoptions ->cinoptions=
If I enter insert mode and start typing the following line
// abc abc abc abc abc abc abc abc
the line breaks at the 40th character, as expected:
// abc abc abc abc abc abc abc
// abc
Also, if a line longer than 40 characters is copied and pasted as
// abc abc abc abc abc abc abc abc
and command gqq
is typed it ends up with the same result as above.
But I've noticed that if I enter insert mode and type the line below
void funAbc(void) { // abc abc abc abc abc abc abc abc
it doesn't break the line. If command gqq
is entered it results in
void funAbc(void) { // abc abc
abc abc abc abc abc abc
I've expected that both inserting line longer than 40 characters or issuing gqq
would break the comments and insert "//" in the next line - something similar to this:
void funAbc(void) { // abc abc
// abc abc abc abc abc abc
I've tried setting 'smartindent'
but it didn't solved the issue.
Is there any option/trick that can change the behavior of these comments starting after code?
I don't think it is. The comment formatting with 'comments' and 'formatoptions' only recognises when the comment string is at start-of-line. The comment starting in the middle of the line is only recognised by the syntax-highlighter, not the formatter. For this reason I don't think it's possible in Vim as shipped. You might be able to find a plugin to do it, but a cursory search on the Vim website didn't turn up anything useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With