Set the textwidth option first, e.g. :set textwidth=77
Then gq will reformat the lines you want.
For example,
- select a block of text ->
gq - you’re in a paragraph and want to reformat the whole paragraph ->
gpip - reformat the next 10 lines ->
gq10j
Here’s how I configure this in my .editorconfig to set a textwidth in
markdown files:
[*.md]max_line_length = 77