Ivan Tomica

(Re)Wrap text in vim

Since I try to use vi/vim editor for almost everything related to editing text and I use it for writing emails too. I use mutt with vim as my text editor but I also have it set up in a way that it wraps text on 80th column:

set editor='vim -c "set textwidth=80" -c "set wrap"'

That’s great, and works great… except when you all of the sudden remember to write something in the middle of existing text, then it all falls apart.


See what I mean? Alright, and here’s how it can be fixed “on the fly”.

To reformat text you can use gq vim command. This will reformat current line, to reformat multiple lines you can select them with:


in visual mode or you can do it with:


which will re-format 13 lines from the cursor (current line + 12 after).


Igor in the comment section pointed out that you can also use:


to re-wrap paragraph and to use:


to re-wrap sentence.

Sysadmin on the everlasting journey of learning.


  1. Igor Pozgaj

    2016-07-15 - 19:37

    “gq” also takes the usual text object, so the easier way to do this would be “gqap” (for a paragraph), or “gqas” (for a sentence). It’s way faster than using the visual mode to select the text object.

    • Ivan Tomica

      2016-07-15 - 20:51

      Thank you for pointing this out to me Igor, I have updated an article accordingly. :-)

Leave a Reply

Your email address will not be published. Required fields are marked *