You can configure different styles of C/C++ indenting by setting 'cindent'
and 'cinoptions'
.
See :help cinoptions-values
for more details on what can be configured and :help C-indenting
for information on C indenting in general.
You can have different settings for C and C++ by placing your configuration in two locations:
In ~/.vim/after/ftplugin/c.vim
:
set cindent
set cinoptions=<the options you want for C>
In ~/.vim/after/ftplugin/cpp.vim
:
set cindent
set cinoptions=<the options you want for C++>
You might also like to take a look at this question about using clang-format for the =
command.
Vim also allows you to set up completely custom indenting using an indent expression. (See :help 'indentexpr'
) This is what the script you mention in the comments does. You can install that for CPP by renaming the file and placing it in the location:
~/.vim/indent/cpp.vim
You can find more details at :help 30.3
and :help indent-expression
.