In my vimrc
I have the following line, which figures all the indentation of my files.
filetype plugin indent on
When writing C programs sometimes I use preprocessor directives like #ifdef foo
and #endif
. When writing one such directive inside a block Vim indents the directive like this.
int main()
{
#ifdef foo
...
#endif
}
But I would like them to be indented as any other statement, i.e.
int main()
{
#ifdef foo
...
#endif
}
indentkeys
might be able to do the job. From :help 'indentkeys'
A list of keys that, when typed in Insert mode, cause reindenting of the current line. Only happens if 'indentexpr' isn't empty.
But my indentexpr
is empty and I have no idea what I should put there; or if there is a better solution.
On the Vim wiki I have read
If you plan on using file type based indentation, don't set 'smartindent' or 'cindent'. You may still set 'autoindent', since it doesn't interfere.
So, since I am using file type based indentation I don't want to use
smartindent
nor cindent
.
How can I achieve my intended indentation for preprocessor directives?
:help cinoptions-values
.