如何为 C 和 C++ 文件中的右大括号配置 Vim 的缩进?

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

我正在处理一些目前格式为 (3 spaces) 的代码(C 和 C++):

void foo() {
   bar();
   }

我想修改代码,让它再缩进一个 space (4 spaces):

void foo() {
    bar();
    }

在 Vim 我设置了:

set expandtab
set shiftwidth=4
set softtabstop=4

但是当我使用 == 或 ='(mark) 自动缩进一行或一组行时,它会给我:

void foo() {
    bar();
}

是否有控制右大括号缩进方式的设置?我目前正在处理的代码的做法是右大括号的缩进量与块的内容相同。但是,Vim 不会缩进右大括号。

假设您正在使用 vim 帮助中的 cindent option. Then you can just set cino=}1s to indent the closing braces by one level of indentation (one shiftwidth). See cinoptions-values 来获取更多信息。