VimtyFive
VimtyFive

Reputation: 13

How to configure Vim's indentation for closing braces in C and C++ files?

I'm working with some code (C and C++) that's presently formatted as (3 spaces):

void foo() {
   bar();
   }

I want to modify the code so that it's indented one more space (4 spaces):

void foo() {
    bar();
    }

In Vim I've set:

set expandtab
set shiftwidth=4
set softtabstop=4

But then when I use == or ='(mark) to autoindent a line or set of lines, it gives me:

void foo() {
    bar();
}

Is there a setting which controls how the closing brace is indented? The practice for the code I'm working on presently is that the closing brace is indented the same amount as the contents of the block. Vim, however, does not indent the closing brace.

Upvotes: 1

Views: 1122

Answers (1)

Kevin
Kevin

Reputation: 30151

Let's assume you're using the cindent option. Then you can just set cino=}1s to indent the closing braces by one level of indentation (one shiftwidth). See cinoptions-values in vim help for more information.

Upvotes: 2

Related Questions