I often use gq
to wrap longer comments to within some number of characters, which works fine if I am using //
or /* /*
to comment my code:
// here is a simple comment that exceeds my line width
// across multiple lines
// here is a simple comment that
// exceeds my line width across
// multiple lines
However, if I have triple-slash comments, e.g. for doxygen, it doesn't work:
/// here is a simple comment that exceeds my line width
/// across multiple lines
/// here is a simple comment that
// exceeds my line width / across
// multiple lines
vim
seems to be including the last slash as part of the text, and not recognizing that it forms part of the comment. How can I fix this? Here is the wrapped result that I want to see when I select triple-slash comments and press gq
:
/// here is a simple comment that
/// exceeds my line width across
/// multiple lines
Note that I don't want to affect the existing behaviour for normal c++
comments.
I am using vim 7.4.52
Adding this to your .vimrc
file should do the trick:
autocmd Filetype c,cpp set comments^=:///
Help about comment formatting can be found at :h format-comments
.
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