How do I get C++ comments to wrap correctly?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How do I get C++ comments to wrap correctly?

Barry Gold
I want to use word-wrap on my C++ comments.

My .vimrc file contains
set tw=75
set fo+=tcjro

But when I type a long C++ style comment, I get
        // This object contains the logic (code and data) for making the
        first pass over the input

I want the second line to start with a // like the first one.

Ideally I'd like it to also work for sh-style comments:
# stuff
and for javadoc comments
/**
 * some stuff that may line-wrap
*/

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I get C++ comments to wrap correctly?

Nikolay Aleksandrovich Pavlov
2017-03-02 20:07 GMT+03:00 Barry Gold <[hidden email]>:

> I want to use word-wrap on my C++ comments.
>
> My .vimrc file contains
> set tw=75
> set fo+=tcjro
>
> But when I type a long C++ style comment, I get
>         // This object contains the logic (code and data) for making the
>         first pass over the input
>
> I want the second line to start with a // like the first one.
>
> Ideally I'd like it to also work for sh-style comments:
> # stuff
> and for javadoc comments
> /**
>  * some stuff that may line-wrap
> */

All of this is done automatically after Vim sources proper filetype
plugin. If you need to do the same stuff without sourcing it, check
`:h 'comments'`.

And note that specifically for C comments this is done by default:
check behaviour of `vim -u NONE -i NONE -N --cmd 'set tw=75
fo+=tcjro'`, it does insert comment leader automatically because
`&comments` option for some reason is set for C by default.

If you do not see this behaviour then you have some plugin and/or
setting interferring.

>
> --
> --
> You received this message from the "vim_use" 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_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I get C++ comments to wrap correctly?

Ben Fritz
In reply to this post by Barry Gold
On Thursday, March 2, 2017 at 11:19:04 AM UTC-6, Barry Gold wrote:

> I want to use word-wrap on my C++ comments.
>
> My .vimrc file contains
> set tw=75
> set fo+=tcjro
>
> But when I type a long C++ style comment, I get
>         // This object contains the logic (code and data) for making the
>         first pass over the input
>
> I want the second line to start with a // like the first one.
>
> Ideally I'd like it to also work for sh-style comments:
> # stuff
> and for javadoc comments
> /**
>  * some stuff that may line-wrap
> */
Do you have filetype plugins turned on in your .vimrc? Either that, or manually setting the 'comments' option will be required for the automatic detection/insertion of comment leaders.

Note that all of these options may be overwritten in the filetype plugin, so it is probably more robust to use an autocmd or filetype plugin of your own to set the desired options per filetype.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I get C++ comments to wrap correctly?

Barry Gold
In reply to this post by Nikolay Aleksandrovich Pavlov
On 3/2/2017 9:30 AM, Nikolay Aleksandrovich Pavlov wrote:

> 2017-03-02 20:07 GMT+03:00 Barry Gold <[hidden email]>:
>> I want to use word-wrap on my C++ comments.
>>
>> My .vimrc file contains
>> set tw=75
>> set fo+=tcjro
>>
>> But when I type a long C++ style comment, I get
>>          // This object contains the logic (code and data) for making the
>>          first pass over the input
>>
>> I want the second line to start with a // like the first one.
>>
>> Ideally I'd like it to also work for sh-style comments:
>> # stuff
>> and for javadoc comments
>> /**
>>   * some stuff that may line-wrap
>> */
> All of this is done automatically after Vim sources proper filetype
> plugin. If you need to do the same stuff without sourcing it, check
> `:h 'comments'`.
>
> And note that specifically for C comments this is done by default:
> check behaviour of `vim -u NONE -i NONE -N --cmd 'set tw=75
> fo+=tcjro'`, it does insert comment leader automatically because
> `&comments` option for some reason is set for C by default.
>
> If you do not see this behaviour then you have some plugin and/or
> setting interferring.
>

Hmmm...

I have the default version of vim that came with cygwin
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jan 27 2017 13:32:56)

Here is my entire .vimrc file:

set autoindent
set nohls
syntax off
set tw=75
set fo+=tcjro
set ws
set ic
set ts=8
set sw=4
map ^V^N :n^V^M
map ^V^W :w^V^M^V^N
map ^K :w^M:e #^M
map v k$hjl
map q F r^M
map g f r^M
map = 3k$h3jl
:map @ k$hjl
set background=light
set ff=unix
let loaded_matchparen = 1

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I get C++ comments to wrap correctly?

Erik Christiansen
In reply to this post by Barry Gold
On 02.03.17 09:07, Barry Gold wrote:
> I want to use word-wrap on my C++ comments.
>
> My .vimrc file contains
> set tw=75
> set fo+=tcjro
>
> But when I type a long C++ style comment, I get
>         // This object contains the logic (code and data) for making the
>         first pass over the input

Here, word wrapping on just typing long lines auto-inserts the comment
leader if fo=croqjlt, but not with fo=qrjt, which I use in composing
emails. You may need an fo tweak, if it is not being changed by plugins.
(We could test your fo setting if its full state were known. What does
":set fo ?" give?)

Erik

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I get C++ comments to wrap correctly?

Barry Gold
On 3/2/2017 8:11 PM, Erik Christiansen wrote:

> On 02.03.17 09:07, Barry Gold wrote:
>> I want to use word-wrap on my C++ comments.
>>
>> My .vimrc file contains
>> set tw=75
>> set fo+=tcjro
>>
>> But when I type a long C++ style comment, I get
>>          // This object contains the logic (code and data) for making the
>>          first pass over the input
> Here, word wrapping on just typing long lines auto-inserts the comment
> leader if fo=croqjlt, but not with fo=qrjt, which I use in composing
> emails. You may need an fo tweak, if it is not being changed by plugins.
> (We could test your fo setting if its full state were known. What does
> ":set fo ?" give?)

formatoptions=croqjlt
(after I made the change you recommended)

But it's _still_ not putting in commend leaders on linewrap.


--
On Beta, we'd have earrings for that. You could buy them in any jewelry store.
http://www.conchord.org/xeno/bdgsig.html

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I get C++ comments to wrap correctly?

Gary Johnson-4
On 2017-03-03, Barry Gold wrote:

> On 3/2/2017 8:11 PM, Erik Christiansen wrote:
> >On 02.03.17 09:07, Barry Gold wrote:
> >>I want to use word-wrap on my C++ comments.
> >>
> >>My .vimrc file contains
> >>set tw=75
> >>set fo+=tcjro
> >>
> >>But when I type a long C++ style comment, I get
> >>         // This object contains the logic (code and data) for making the
> >>         first pass over the input
> >Here, word wrapping on just typing long lines auto-inserts the comment
> >leader if fo=croqjlt, but not with fo=qrjt, which I use in composing
> >emails. You may need an fo tweak, if it is not being changed by plugins.
> >(We could test your fo setting if its full state were known. What does
> >":set fo ?" give?)
>
> formatoptions=croqjlt
> (after I made the change you recommended)
>
> But it's _still_ not putting in commend leaders on linewrap.

What about the results of this?

    :verbose set comments?

The string of comma-separated values must include

    ://

or Vim won't recognize // as a comment leader.

Regards,
Gary

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I get C++ comments to wrap correctly?

Barry Gold
On 3/3/2017 9:55 AM, Gary Johnson wrote:
On 2017-03-03, Barry Gold wrote:
On 3/2/2017 8:11 PM, Erik Christiansen wrote:
On 02.03.17 09:07, Barry Gold wrote:
I want to use word-wrap on my C++ comments.

My .vimrc file contains
set tw=75
set fo+=tcjro

But when I type a long C++ style comment, I get
        // This object contains the logic (code and data) for making the
        first pass over the input
Here, word wrapping on just typing long lines auto-inserts the comment
leader if fo=croqjlt, but not with fo=qrjt, which I use in composing
emails. You may need an fo tweak, if it is not being changed by plugins.
(We could test your fo setting if its full state were known. What does
":set fo ?" give?)
formatoptions=croqjlt
(after I made the change you recommended)

But it's _still_ not putting in commend leaders on linewrap.
What about the results of this?

    :verbose set comments?

The string of comma-separated values must include

    ://

or Vim won't recognize // as a comment leader.
:verbose set comments
E519: Option not supported: comments


-- 
On Beta, we'd have earrings for that. You could buy them in any jewelry store.
http://www.conchord.org/xeno/bdgsig.html

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I get C++ comments to wrap correctly?

Gary Johnson-4
On 2017-03-03, Barry Gold wrote:
> On 3/3/2017 9:55 AM, Gary Johnson wrote:

>> What about the results of this?
>>
>>     :verbose set comments?
>>
>> The string of comma-separated values must include
>>
>>     ://
>>
>> or Vim won't recognize // as a comment leader.
>
> :verbose set comments
> E519: Option not supported: comments

Well, that would explain the problem.  The vim you're using is
probably the tiny or small version.  I just ran a small version and
confirmed that the comments option is not supported.

The Cygwin base install comes with only vim-minimal.  You'll just
need to install the vim package.  It's currently at 8.0.329.

    VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Feb 15 2017 20:45:09)
    Included patches: 1-329
    Modified by <[hidden email]>
    Compiled by <[hidden email]>
    Huge version without GUI.  Features included (+) or not (-):

You'll want the vim-common package, too.  I don't remember whether
or not it gets installed automatically when you install vim.

There's also a vim-doc package, but I don't have that one installed
and yet I have all the documentation available.  I don't know what's
going on there.  It wouldn't hurt to install vim-doc, too, though.

Regards,
Gary

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I get C++ comments to wrap correctly?

Barry Gold
On 3/3/2017 12:49 PM, Gary Johnson wrote:

> On 2017-03-03, Barry Gold wrote:
>> On 3/3/2017 9:55 AM, Gary Johnson wrote:
>>> What about the results of this?
>>>
>>>      :verbose set comments?
>>>
>>> The string of comma-separated values must include
>>>
>>>      ://
>>>
>>> or Vim won't recognize // as a comment leader.
>> :verbose set comments
>> E519: Option not supported: comments
> Well, that would explain the problem.  The vim you're using is
> probably the tiny or small version.  I just ran a small version and
> confirmed that the comments option is not supported.
>
> The Cygwin base install comes with only vim-minimal.  You'll just
> need to install the vim package.  It's currently at 8.0.329.
>
>      VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Feb 15 2017 20:45:09)
>      Included patches: 1-329
>      Modified by <[hidden email]>
>      Compiled by <[hidden email]>
>      Huge version without GUI.  Features included (+) or not (-):
>
> You'll want the vim-common package, too.  I don't remember whether
> or not it gets installed automatically when you install vim.
>
> There's also a vim-doc package, but I don't have that one installed
> and yet I have all the documentation available.  I don't know what's
> going on there.  It wouldn't hurt to install vim-doc, too, though.
>
> Regards,
> Gary
>
I went to the cygwin installer. I have vim-minimal and vim-common. I
don't seem to be offered any other options for vim.

Then I went to the vim website, downloaded and installed vim80. But it
appears I got only a GUI vim (gvim), not a command-line vim.

*shrug*


--
On Beta, we'd have earrings for that. You could buy them in any jewelry store.
http://www.conchord.org/xeno/bdgsig.html

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I get C++ comments to wrap correctly?

Gary Johnson-4
On 2017-03-05, Barry Gold wrote:

> On 3/3/2017 12:49 PM, Gary Johnson wrote:
> >On 2017-03-03, Barry Gold wrote:
> >>On 3/3/2017 9:55 AM, Gary Johnson wrote:
> >>>What about the results of this?
> >>>
> >>>     :verbose set comments?
> >>>
> >>>The string of comma-separated values must include
> >>>
> >>>     ://
> >>>
> >>>or Vim won't recognize // as a comment leader.
> >>:verbose set comments
> >>E519: Option not supported: comments
> >Well, that would explain the problem.  The vim you're using is
> >probably the tiny or small version.  I just ran a small version and
> >confirmed that the comments option is not supported.
> >
> >The Cygwin base install comes with only vim-minimal.  You'll just
> >need to install the vim package.  It's currently at 8.0.329.
> >
> >     VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Feb 15 2017 20:45:09)
> >     Included patches: 1-329
> >     Modified by <[hidden email]>
> >     Compiled by <[hidden email]>
> >     Huge version without GUI.  Features included (+) or not (-):
> >
> >You'll want the vim-common package, too.  I don't remember whether
> >or not it gets installed automatically when you install vim.
> >
> >There's also a vim-doc package, but I don't have that one installed
> >and yet I have all the documentation available.  I don't know what's
> >going on there.  It wouldn't hurt to install vim-doc, too, though.
> >
> >Regards,
> >Gary
> >
> I went to the cygwin installer. I have vim-minimal and vim-common. I
> don't seem to be offered any other options for vim.
>
> Then I went to the vim website, downloaded and installed vim80. But
> it appears I got only a GUI vim (gvim), not a command-line vim.

My Cygwin installer, setup-x86.exe, version 2.877 (32 bit), when
using http://mirrors.kernel.org as the download site, with the View
set to Full and the Search box containing "vim" (no quotes) shows
8 packages:

    fzf-vim
    gvim
    vim
    vim-clang-format
    vim-common
    vim-debuginfo
    vim-doc
    vim-minimal

The package you want is the vim package.

Regards,
Gary

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I get C++ comments to wrap correctly?

Barry Gold
On 3/6/2017 9:19 AM, Gary Johnson wrote:

> On 2017-03-05, Barry Gold wrote:
>> On 3/3/2017 12:49 PM, Gary Johnson wrote:
>>> On 2017-03-03, Barry Gold wrote:
>>>> On 3/3/2017 9:55 AM, Gary Johnson wrote:
>>>>> What about the results of this?
>>>>>
>>>>>      :verbose set comments?
>>>>>
>>>>> The string of comma-separated values must include
>>>>>
>>>>>      ://
>>>>>
>>>>> or Vim won't recognize // as a comment leader.
>>>> :verbose set comments
>>>> E519: Option not supported: comments
>>> Well, that would explain the problem.  The vim you're using is
>>> probably the tiny or small version.  I just ran a small version and
>>> confirmed that the comments option is not supported.
>>>
>>> The Cygwin base install comes with only vim-minimal.  You'll just
>>> need to install the vim package.  It's currently at 8.0.329.
>>>
>>>      VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Feb 15 2017 20:45:09)
>>>      Included patches: 1-329
>>>      Modified by <[hidden email]>
>>>      Compiled by <[hidden email]>
>>>      Huge version without GUI.  Features included (+) or not (-):
>>>
>>> You'll want the vim-common package, too.  I don't remember whether
>>> or not it gets installed automatically when you install vim.
>>>
>>> There's also a vim-doc package, but I don't have that one installed
>>> and yet I have all the documentation available.  I don't know what's
>>> going on there.  It wouldn't hurt to install vim-doc, too, though.
>>>
>>> Regards,
>>> Gary
>>>
>> I went to the cygwin installer. I have vim-minimal and vim-common. I
>> don't seem to be offered any other options for vim.
>>
>> Then I went to the vim website, downloaded and installed vim80. But
>> it appears I got only a GUI vim (gvim), not a command-line vim.
> My Cygwin installer, setup-x86.exe, version 2.877 (32 bit), when
> using http://mirrors.kernel.org as the download site, with the View
> set to Full and the Search box containing "vim" (no quotes) shows
> 8 packages:
>
>      fzf-vim
>      gvim
>      vim
>      vim-clang-format
>      vim-common
>      vim-debuginfo
>      vim-doc
>      vim-minimal
>
> The package you want is the vim package.
>
> Regards,
> Gary
>

That did it. Thank you.


--
On Beta, we'd have earrings for that. You could buy them in any jewelry store.
http://www.conchord.org/xeno/bdgsig.html

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...