1

I have the following snippet of text and I want the "blah" lines to not wrap.

\begin{itemize}
    \item
      Blah blah blah blah blah blah blah
      blah blah blah blah blah blah Blah
      blah blah blah blah blah blah blah
    \item
      Blah blah blah blah blah blah blah
      blah blah blah blah blah blah Blah
      blah blah blah blah blah blah blah
\end{itemize}

I issue :set tw=9999, then the following:

:g/\<item$/+1 norm gq/\<item/-1
:% g/\<item$/+1 norm gq/\<item/-1

Neither seem to do anything, but simply putting the cursor on the first "blah" line and issuing gq/\<item/-1 works fine:

\begin{itemize}
    \item
      Blah blah blah blah blah blah blah blah blah blah blah blah blah Blah blah blah blah blah blah blah blah
    \item
      Blah blah blah blah blah blah blah
      blah blah blah blah blah blah Blah
      blah blah blah blah blah blah blah
\end{itemize}

Obviously, I'm doing something wrong. Can anyone point out my error?

3
  • 1
    If you'd finish a command with ^M normally, then you still need that in the :norm.
    – Antony
    May 15 '17 at 17:50
  • 2
    And there's J for joining lines. Maybe that would be more useful to you here.
    – Antony
    May 15 '17 at 17:52
  • Thanks, antony, on both answers. If you want to formally post these as the answer, I'll gladly accept them.
    – user36800
    May 15 '17 at 19:40
1

Thanks to antony for point out that the problem is solved by adding a ^M to the comand:

:g/\<item$/+1 norm gq/\<item/-1^M

I get the ^M by first pressing ctrl-V, then either ctrl-M or the Carriage Return key.

Antony also pointed out the gq command can be replaced by the J command (for Join). That works for this example. In a more complex situation, where a body of text might have under-length and over-length lines due to extensive revision, gq is needed. It formats the entire "paragraph".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.