1

I'd like = to indent block C-style comments like this:

/*
  Comment.
*/

not this:

/*
  Comment.
 */

Note the extra space before the last *. (I would like to automatically align the first / and the last * at the current indentation level.)

What is a simple way, preferably compatible with autoindent, to specify this in my .vimrc?

1 Answer 1

3

You can adjust the indent of the end comment by setting the 'comments' option. e.g.:

:set comments=s:/*,m:\ ,e-3:*/

This is documented at :help 'comments' and :help format-comments.

You might also want to look into how you currently have it set by using the command: :verbose set comments.

You probably should also consider using 'cindent' instead of 'autoindent', and if you do so, you may want to take a look at: :help cino-C, which will allow you to tweak the indent of that middle line.

2
  • 1
    Very helpful. I will add, for future visitors, that putting the above in my .vimrc didn't immediately work, since there are ftplugin settings overriding (which is also revealed by :verbose set comments). Commented Mar 27, 2018 at 12:52
  • 1
    Use the after-directory to set your own personal 'filetype' settings, e.g. ~/.vim/after/ftplugin/c.vim. For more help see :h after-directory. Commented Mar 27, 2018 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.