I have seen partial solutions over the internet but none that really satisfied me: what do I have to put into my .vimrc (ideally I don’t want to chance any syntax/*.vim file) such that in all .c/cpp/h files that I open, I get automatic folding of #ifdef ... #endif sections?
I have seen partial solutions over the internet but none that really satisfied me:
Share
If the only type of folding that you want is the
#ifdefsections, the easiest way is to create a file~/.vim/after/ftplugin/c.vim(you may also need to do this incpp.vim, I’m not sure) with the following content:If you really want to put it in
.vimrcrather than using the~/.vim/after/structure, you can do something like this:You might also want to consider using:
As that will catch
#if defined(...),#ifdef,#ifndef,#if 0etc as well as#ifdef.Doing this with syntax folding is more challenging as you’ll have to change the syntax specification as it doesn’t support this as standard.