views:

370

answers:

2

Not a dup of http://stackoverflow.com/questions/391710/in-vim-what-is-the-simplest-way-to-join-all-lines-in-a-file-into-a-single-line, as I specifically mean to use the gq reformating functionality.

I used to write latex in vim using 80 character textwidth. However, I've now switched to an infinite textwidth, so my lines go on forever.

Vim's reformating (gqap for example), combines a few lines into a paragraph, wrapping them at 80 characters. I'd like it to instead combine them into a single line.

ie

Without a \clang{goto} statement in the HIR, we must instead use conditional
statements to check the iteration number.

should reformat into

Without a \clang{goto} statement in the HIR, we must instead use conditional statements to check the iteration number.

when it is highlighted and gq is pressed.

+2  A: 

Why don't you just "J" the lines after you select them?

depesz
J as in join, to make it memorable
Christian
My fingers are used to gqap (and other forms of gc). I don't want to have one command for latex and another for other forms of editing.
Paul Biggar
@Paul: sorry, but this argument doesn't make sense. If you know command "cp" you shouldn't use "mv"? If you're used to hammer, you'll prefer it to screwdriver when you'll need to use a screw?
depesz
@depesz: I'm trying to figure out why gq isnt working the way I thought it should. gq is the reformat command. Just because this particular reformat is similar to joining doesnt mean I should start using J. Your analogy makes no sense. FYI, J doesnt work in some cases, such as in the middle of 3 lines, which I would expect gqap to (with the appropriate settings).
Paul Biggar
'vapJ' (or maybe 'vipJ') should be the same as 'gqap' with 'set tw=9999'
Maxim Kim
+3  A: 

If you don't like "J" as depesz suggested then do

:set tw=9999

Then do 'gq'. Adjust tw to your needs.

Maxim Kim
Bizarre. Why does this work for `tw=9999`, but not for `tw=0`?
Paul Biggar
:h gq (If the 'textwidth' option is 0, the formatted line length is the screen width (with a maximum width of 79).
Maxim Kim
Missed that, despite reading that section more than once. Thanks.
Paul Biggar