Joe Sewell
Joe Sewell

Reputation: 306

How does one rewrap text in a column in Vim?

I have column-oriented text of the form:

TR #  DATE        DESCRIPTION                  PROGRAMMER
----- ----------- ---------------------------  -----------
12345 01-APR-2014 This is an April Fool's      Joe Sewell
                  joke. Not!

Now I want to widen the DESCRIPTION column and rewrap that column only to the new width. Let's say, for the sake of this question, I would add the spaces myself so it would look more like this:

TR #  DATE        DESCRIPTION                        PROGRAMMER
----- ----------- ---------------------------------  -----------
12345 01-APR-2014 This is an April Fool's            Joe Sewell
                  joke. Not!

Now comes the bit I need help on. I want to perform a visual block selection (CTRL-V or CTRL-Q in gvim) on the DESCRIPTION column and perform an ex command or mapping to rewrap the text to the selected width, producing:

TR #  DATE        DESCRIPTION                        PROGRAMMER
----- ----------- ---------------------------------  -----------
12345 01-APR-2014 This is an April Fool's joke.      Joe Sewell
                  Not!

I can deal with the subsequent lines having trailing spaces, if necessary. I want none of the rest of the text on the selected lines affected. (Those familiar with EVE under OpenVMS, this is equivalent to block selecting a chunk of text and, with the EDT keypad, typing GOLD-8.) I don't want indentation changed.

Upvotes: 4

Views: 1314

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172590

My FormatToWidth plugin provides a <Leader>gq command with which you can achieve this: enter image description here

Upvotes: 4

Wiener Boat
Wiener Boat

Reputation: 446

Have you considered moving the DESCRIPTION column to another buffer, setting your desired textwidth for that buffer (:set textwidth=yournumber), formatting with gq, then moving back to the original location?

Upvotes: 2

Related Questions