When editing files that I limit in my .vimrc to tw=80, when I come back to edit them later, the line-lengths end up all over the place. e.g.
lets say for the sake of argument that this line hits 80 characters
there and continues on the next line as normal
After editing…
lets say for the sake of argument (edit edit edit edit) that this
line hits 80 characters
there and continues on the next line as normal
Instead of
lets say for the sake of argument (edit edit edit edit) that this
line hits 80 characters there and continues on the next line as
normal
Anyone know what I can do to fix this behaviour?
Best Answer
You can use the "
gq
" normal-mode command to reformat text. It works on a visual selection, or with a motion. For example, you can use the text-object "ap
" (which can be used in place of a motion) which means "a paragraph" (the current paragraph that the cursor is on):Or you could visually select the paragraph(s) you want to reformat and just type "
gq
".Another trick is to add "a" and optionally "w" to the 'formatoptions' option:
This will automatically reformat paragraphs as you type, without needing to resort to "
gq
".See: