-1

I am using foldmethod=syntax in my .vimrc file. It works well with C functions like this one:

int some_fun(int i) {
  return i;
}

However, it won't work with functions, which have a break line in the first line:

int some_fun2(int i,
  int i2) {
  return i;
}

Can I make Vim understand that fold should begin not where { is but where the function definition begins?

1 Answers1

2

Yes, but you have to augment the syntax/c.vim syntax file with a proper definition. The following line is responsible for the default behavior of folding {...} blocks:

syn region    cBlock      start="{" end="}" transparent fold

You have to override that with one that considers function definitions (whose syntax patterns you'll also find in that file), and put that into ~/.vim/after/syntax/c.vim. A challenge with that is that the start match for the function definition will now obscure the default matching, so elements like int and the function name may lose its highlighting. Maybe a zero-width match may prevent that, or you can use the matchgroup. If all of that sounds to be well over your head, don't bother. Maybe the fact that you haven't found such syntax modification means that it's too hard to do.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324