The problem with pure regex based solutions, is that there would be a few false-positives, like in:
/*bar*/
char const* p = "/*";
/* bar */
/// foo
char const* e = "*/";
/*
in strings would be matched as well.
I though at first that we could get around it with [*
and ]*
, but unfortunately, they are also regex based.
Though, we can have the correct behaviour with {skip}
parameter in search()
:echo search('/\*\_.\{-}\*/\|//' ,'',0,0, 'synIDattr(synID(line("."), col("."), 0), "name") =~ "\\cstring"')
which is best defined as a mapping
" for a mapping defined this way, we have to double the '\' before the '|' to express the _or_
nnoremap <silent> [< :<c-u>call search('/\*\_.\{-}\*/\\|//' ,'',0,0, 'synIDattr(synID(line("."), col("."), 0), "name") =~ "\\cstring"')<cr>