简体   繁体   English

如何配置Vim的缩进来关闭C和C ++文件中的花括号?

[英]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): 我正在使用一些当前格式为(3个空格)的代码(C和C ++):

void foo() {
   bar();
   }

I want to modify the code so that it's indented one more space (4 spaces): 我想修改代码,使其缩进一个空格(4个空格):

void foo() {
    bar();
    }

In Vim I've set: 在Vim中,我设置了:

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: 但是当我使用==或='(mark)自动缩进一行或一组行时,它会给我:

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. 但是,Vim不会缩进右括号。

Let's assume you're using the cindent option . 假设您正在使用cindent选项 Then you can just set cino=}1s to indent the closing braces by one level of indentation (one shiftwidth ). 然后,您只需将cino=}1s设置为以一个缩进级别(一个shiftwidth )缩进shiftwidth括号即可。 See cinoptions-values in vim help for more information. 有关更多信息,请参见vim帮助中的cinoptions-values

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM