1

I have the following in my .vimrc to indent the whole file:

nnoremap cu gg=G``

I have a problem using this in source files that have

#ifdef __cplusplus
extern "C"
{
#endif

// code

#ifdef __cplusplus
}
#endif

This makes vim shift all the functions one tab to the right. This makes it inconsistent with my colleagues who don't use vim and it also annoys me. Is there a way to tell vim to ignore these brakets of extern "C"?

1 Answer 1

1
setlocal cinoptions=E-s

See :h cinoptions-values.

Also make sure that :h 'equalprg' is set to empty, so the internal Vim formatter is used. If not, see man pages of an external formatter tool whatever it is.

4
  • I added this line to my .vimrc, as well as set equalprg="" but when I press c-u, it still considers the extern C brakets. Do I miss anything? Jun 30, 2020 at 9:26
  • 1
    @SalahuddinAhmed In vimrc you have to use set (not setlocal) to change the default setting. Make sure you've read and understood :h options.txt
    – Matt
    Jun 30, 2020 at 9:47
  • 1
    @SalahuddinAhmed BTW. The right syntax is set equalprg= (which is Vim's default anyway). The double-quote stands for a comment mark, so it doesn't hurt (unless it's followed by another option), but it looks strange, to say the least.
    – Matt
    Jun 30, 2020 at 9:56
  • Now it works. Could you please edit the answer to set instead of setlocal and add set equalprg= so that it becomes complete and clear for future viewer. Thanks Jun 30, 2020 at 10:50

Your Answer

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

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