One thing that I often need to do is reformat a code comment with gq or gw. For example, I often want to convert something like this:
// Lorem ipsum
// dolor
// sir
// amet
int foo(int x) {
return 17;
}
into this:
// Lorem ipsum dolor sir amet
int foo(int x) {
return 17;
}
Is there a vim motion I can use to select the entire comment block under the cursor? I tried using gq} and gqipbut they also reformat the code under the comment, which is too much.
// Lorem ipsum dolor sir amet
int foo(int x) { return 17; }
So far the best I could think is manually counting lines, using something like gq4j. But there ought to be a better way...
ono <silent> ix :exe search('.$', 'W', 0, 0, {-> synstack(line('.'), col('.'))->map('synIDattr(v:val, "name")')->match('\ccomment') != -1}) ? 'norm! k' : ''<cr>