Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
Vim comes with an extensive documentation, try :h shiftwidth. – romainl May 12 '13 at 11:19
up vote 0 down vote accepted

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) {

when you put a matching '}', vim will indent it properly.

if (a > 0) {

Read this documentation for more clarity.

share|improve this answer
I tried it, but affter pressing enter at the curly brace, it puts the cursor to the beginning of the line. – user223787 May 12 '13 at 11:25
are you typing the closing curly brace before pressing enter? Is there a plugin that auto closes brackets enabled? – draxxxeus May 12 '13 at 11:31
yes. No plugins – user223787 May 12 '13 at 12:02
Don't type the closing }. It is interpreted as the end of the statement and hence vim is not auto-indenting. – draxxxeus May 12 '13 at 12:05
I dind't type the closing }. Anyway, thanks for your help. I don't know what does that option do, but I will add it to .vimrc :) – user223787 May 12 '13 at 12:22

I can recommend this screencast by Drew Neil which will explain how tabstop, softtabstop, shiftwidth and expandtab work together.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .