If you only need the folding type, this is the #ifdef section, the easiest way is to create a ~/.vim/after/ftplugin/c.vim (you may also need to do this in cpp.vim , I'm not sure) with the following content:
set foldmarker=#ifdef,#endif set foldmethod=marker
If you really want to put it in .vimrc instead of using the ~/.vim/after/ structure, you can do something like this:
autocmd FileType *.[ch]{,pp} call FoldPreprocessor() function! FoldPreprocessor() set foldmarker=#ifdef,#endif set foldmethod=marker endfunction
You may also consider using:
set foldmarker=#if,#endif
Since it will catch #if defined(...) , #ifdef , #ifndef , #if 0 etc., as well as #ifdef .
Doing this with syntax folding is more complicated since you have to change the syntax specification as it does not support this as a standard.
source share