5

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.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
derobert
  • 49,731
  • 15
  • 94
  • 124

2 Answers2

8

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.

jamessan
  • 41,569
  • 8
  • 85
  • 85
  • Exactly what I was thinking, +1 – Carl Smotricz Dec 09 '09 at 14:04
  • Yes, I'm giving it a motion. And it works on other lines, so I'm pretty sure it works. I've been trying gq, which normally works. I'll update the question. – derobert Dec 09 '09 at 14:20
  • The only situations where gq shouldn't be wrapping a line are 1) the line has no whitespace, 2) the line is shorter than 'textwidth', 3) 'formatexpr'/'formatprg' is set and the function/program that is invoked doesn't wrap the text. Since none of these cases seem to be in play here, I'm not sure why you're seeing this behavior. – jamessan Dec 09 '09 at 15:48
  • I've added some steps to reproduce a similar problem. Does this only happen for me? I tried it with gvim -u NONE, so it's not my vimrc. – derobert Dec 09 '09 at 16:40
  • Thanks for the clarification. The problem is the b setting in `formatoptions`. That's telling Vim to only wrap the text added during the last insertion. – jamessan Dec 09 '09 at 16:58
  • Thanks! It is indeed the `b` in `formatoptions`. Please edit this in to your answer so I can accept it! – derobert Dec 10 '09 at 18:34
1

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?

Carl Smotricz
  • 66,391
  • 18
  • 125
  • 167
  • Please see my clarification & steps to reproduce. – derobert Dec 09 '09 at 16:41
  • I wasn't aware that a small motion like left would be enough to cause wrap, but sure enough! I faithfully followed your steps to reproduce and achieved a wrap just before "But," which looks entirely correct to me. I'm using vim 7.2.245 out of the box on Ubuntu 9.10 . I can do more testing if you tell me what. – Carl Smotricz Dec 09 '09 at 16:56
  • "out of the box" was a lie. my .vimrc does: " Carl's vim settings syn on set sts=3 set ai set sw=3 – Carl Smotricz Dec 09 '09 at 16:58
  • @Carl: Your distro (Ubuntu) probably has some customization in /etc/vim/vimrc and /etc/vim/gvimrc – derobert Dec 10 '09 at 18:35
  • @Carl: That `-u NONE` will skip system initialization in /etc as well; see `:help initialization` inside vim. – derobert Dec 10 '09 at 18:38
  • Re-tested with -u NONE and now it's behaving "badly" for me too. See update of my answer. – Carl Smotricz Dec 10 '09 at 20:24