Tuesday, January 16, 2018

Alignment that contains comment lines that has ending "{"

The version I used is 8.9.586.
I noticed that vim alignment for c program is kind of strange. For example, in the following example, when line "//if(2) {" is in front of line "if(1) {", the alignment is fine (used gg=G to align the whole file). But if I switch the order of these two lines, the last "}" doesn't align correctly. Is this a known problem of vim? Any work around?

Similar question is for the match command "%": It seems the % command take the ending "{" in a comment line into account as well. In the following example, the first "{" can't find any matching "}". Is there a way to solve this problem? Thanks.
--Karl

#include <stdio.h>

int main()
{
    //if (2) {
    if (1) {
        printf("1\n");
    }
}

=====================
#include <stdio.h>

int main()
{
    if (1) {
        //if (2) {
        printf("1\n");
    }
    } <<<< not aligned well.

No comments:

Post a Comment