What does shiftwidth do in VIM editor
Lets say you have set shiftwidth=2
Firstly, you need to make sure that the file that a .c extension. Either by using
$ vim foo.c
for a new file or saving the file with a .c extension.
Now type
if (a > 0) {
and press enter. The next line will automatically be indented.
if (a > 0) {
foo();
when you put a matching '}', vim will indent it properly.
if (a > 0) {
foo();
}
Read this documentation for more clarity.
I can recommend this screencast by Drew Neil which will explain how tabstop, softtabstop, shiftwidth and expandtab work together.