Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-write asterisks in C++ comments

Tags:

vim

Is there a way for me to configure my vimrc so that, when writing a multi-line comment in C++, Java, or other languages, like

/* f
 * o
 * o
 */

, I could get the asterisk and space to appear whenever I'm in a comment and press return to start a new line?

If I have not worded my question well enough, please tell me.

Thank you in advance for any help.

like image 391
joshhartigan Avatar asked Oct 29 '25 08:10

joshhartigan


1 Answers

That is controlled via 'formatoptions':

:set formatoptions+=r

To also enable this for o and O commands:

:set formatoptions+=o

See all available options at :help fo-table.

Note that this depends on the correct 'comments' setting, but the default already has the right definition for /* ... */ multiline comments.

like image 69
Ingo Karkat Avatar answered Oct 31 '25 06:10

Ingo Karkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!