derobert
derobert

Reputation: 51147

Wrap long lines in Vim?

I've noticed that gq does not work when I paste in a long line. For example, with a textwidth=72 and formatoptions=tcroqbnl, gq refuses to wrap this (in insert mode, I pasted the entire label contents, and then exited insert mode with ESC):

<label for="contact_reason_1">To get assistance with or to confirm a tire replacement recommendation</label>

If I add a line break in (after "to", for example), it'll wrap then. The funny thing is if I join the line back together, it'll happily wrap it again. So VIM seems to somehow be remembering "oh, this is one paste, don't wrap it".

How do I turn that feature off? I'd like gq in command mode to always work. Taking l out of formatoptions did not seem to help (and it shouldn't, this isn't insert mode).


clarification

Yes, I'm using a motion command, in particular, gq<Right>. formatexpr and formatprog are both unset. If it matters, this is in gvim on Debian GNU/Linux, vim version 7.2p284.

steps to reproduce

  1. Pop up gvim on an open file.
  2. Press i to get into insert mode, then type This is a long line. A long line. But not wrappable yet. Or yet. Soon.
  3. Press ESC, then I. Type Now putting text in front of the long line. note: there is a space after the final period, can't get SO to show it, except when this note is here. FUN.
  4. Press ESC, then A. Type And some after. note: space before the And, same SO problem.
  5. Press ESC one last time. Now try gq<Left>, note it only wraps And some after.; I can't get vim to wrap the rest of the line (without going into insert mode and doing a line break by hand, then it works).

Fixing this state is doable; putting a newline after "now" and then hitting undo makes line wrap work again. WTF.

Upvotes: 6

Views: 7936

Answers (2)

Carl Smotricz
Carl Smotricz

Reputation: 67760

I find that if I select the line before doing the gq, it works fine. Doesn't gq want to be combined with some text selection operation to work?

UPDATE

I confirm the bug. Running vim -u NONE, my formatoptions are vt.

Maybe Bram Molenar or at least the vim community would be interested?

Upvotes: 1

jamessan
jamessan

Reputation: 42667

gq isn't enough to wrap the text. You have to give it a motion over which to wrap (like gqj) or tell it to wrap the current line with gqq. Are you sure you're not just mistyping it?

If you aren't, what are the formatexpr and formatprg options set to, if anything?

Update
The problem is the b setting in formatoptions. That's telling Vim to only wrap the text added during the last insertion.

Upvotes: 9

Related Questions