What does shiftwidth do in VIM editor
I read this about shiftwidth option on Google: To change the number of space characters inserted for indentation, use the 'shiftwidth' option.
Ok Ok, but what's that more exactly? How can I try this to see what really happens? I created a new C file then added an IF confition, but nothing happens during identation:
if (a > 0) { nothing happens here }
Thank you!
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.