Using `gq` or `gw` to format text
If you type a really long line in Vim, Vim soft-wraps it at the end of the
window, but in the file it’s still one line. If you type gq or gw followed
by a movement, Vim formats the text based on the movement you selected. For
instance, gwip will format the paragraph under the cursor (gw inside i
paragraph p), gwG will format from the cursor to the end of the file (G).
Both gw and gq format the same way. However, gw keeps the cursor position
while gq does not.
Photo by the author