0

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;
}
4

2 回答 2

0

将以下内容添加到您的 vimrc 中。这将启用文件类型插件并获得所需的缩进。

 filetype plugin indent on

根据:h smartindent. 除非您放入大括号,否则智能缩进只会插入制表符。

Normally 'autoindent' should also be on when using 'smartindent'.
An indent is automatically inserted:
- After a line ending in '{'.
- After a line starting with a keyword from 'cinwords'.
- Before a line starting with '}' (only with the "O" command).
When typing '}' as the first character in a new line, that line is
given the same indent as the matching '{'.
于 2013-06-19T02:09:53.850 回答
0

尝试这个:

#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;
}
于 2013-06-19T01:52:59.240 回答