Open a c file and then type:


and then hit:


It becomes


Is this an intended behavior? Is there a way to change this? I prefer it to be retained as is because most projects have it like that.

Here are some settings that I have:

set fr          # c
set cindent     # cindent
set ai          # autoindent
set si          # smartindent
set indentexpr  #    
  • 1
    Well, that command reformats the entire file. How it does indentation depends on your configuration. What does :set ai? si? cidnent? indentexpr? ft? return? And if you don't have syntatically correct C code then the formatting might not look so great (garbage-in, garbage-out). Is there some code surrounding what you've shown?
    – B Layer
    Jan 12, 2019 at 6:56
  • suggest, as a reasonable suggestion: place the return type (which is part of the function signature) on the same line as the rest of the function signature Jan 12, 2019 at 8:39
  • @BLayer, updated that. It is syntactically valid code. I am able to reproduce even with int and main though.
    – Nishant
    Jan 12, 2019 at 18:27
  • @user3629249, most projects like Linux and FreeBSD uses this convention. So I was trying to use that.
    – Nishant
    Jan 12, 2019 at 18:27

1 Answer 1


Open a C file and have a look at cinoptions

set cinoptions?

Most likely this is empty. Now add t0.

set cinoptions+=t0

Reformat your C code, and the type should not be indented anymore.

See :help 'cinoptions' and :help cinoptions-values. There you find that indenting the type by one 'shiftwidth' is the default (when on line for it own).

If cinoptions is not empty and already contains a entry tN (N is a number), you have to remove it first:

set cinoptions-=tN    "replace N with actual number

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.