Why does VIM not indent two for-loop lines correctly?

advertisements

I entered the following code in VIM, why does it do not indenting properly ? Here I wanna repeat the same loop 3 times, they are not nested loops. This code is just do describe my problem.

#include <stdio.h>

int main() {
  int c;
  for (c = 0; c < 100; ++c)
    printf("%d\t%c\n", c, c);
    for (c = 0; c < 100; ++c)
      printf("%d\t%c\n", c, c);
      for (c = 0; c < 100; ++c)
        printf("%d\t%c\n"; c, c)
  return 0;
}

This is my .vimrc configuration

set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set smartindent

Is anything wrong in this settings ?

The same code in emacs looks like this

#include <stdio.h>

int main() {
  int c;
  for (c = 0; c < 100; ++c)
    printf("%d\t%c", c, c);
  for (c = 0; c < 100; ++c)
    printf("%d\t%c", c, c);
  for (c = 0; c < 100; ++c)
    printf("%d\t%c", c, c);
  return 0;
}


Try this:

#include <stdio.h>

int main() {
  int c;
  for (c = 0; c < 100; ++c) {
    printf("%d\t%c\n", c, c);
    for (c = 0; c < 100; ++c) {
      printf("%d\t%c\n", c, c);
      for (c = 0; c < 100; ++c) {
        printf("%d\t%c\n"; c, c)
      }
    }
  }
  return 0;
}