Search code examples
vimindentation

vim automatically indent comma exception


VIM automatically indent the following code, .b = 2 line indentation looks very bad.

struct foo test(void) { 
    return (struct foo) {
           .a = 1,
                .b = 2,
    };
}

How can I change indentation settings so it would look like this?

struct foo test(void) {
    return (struct foo) {
         .a = 1,
         .b = 2,
    };
}

Solution

  • You need to set the cinoptions :

    :set cino+=J1 
    

    After that indent it with the command = (ex: indent all the file gg=G)