Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>The Bad News</strong></p> <p>I'm not sure something like what you suggest exists, although it definitely could - Vim surprises me every day. I'm sure someone on SO knows.</p> <p><strong>The Good News</strong></p> <p>There's a better way to achieve what you want! Or, what I <em>think</em> you want. You can tell Vim to perform a formatting operation on a given region of text. All you have to do is set <code>textwidth</code> to the maximum width you'd like, then use <code>gq{motion}</code> to format the text that <code>{motion}</code> moves over. For your example:</p> <pre><code>/* Line 1 of some large comment block, hopefully it contains well written documentation. I'd now like 'hopefully' to be on the first line. */ </code></pre> <p>You would simply set a reasonable <code>textwidth</code> – here it looks like you're going for about 50 – and then format the comment. Put your cursor on the first <code>/</code>, and</p> <pre><code>:set textwidth=50 gq% </code></pre> <p><strong>The Catch</strong></p> <p><em>But wait,</em> you say, <em>that didn't work!</em> </p> <p>Whoops. You're right. What appears to have happened here is that Vim doesn't understand this format. When I followed my own instructions, I saw this, though your mileage may vary:</p> <pre><code>/* Line 1 of some large comment block, hopefully it contains well written documentation. I'd now like 'hopefully' to be on the first line. */ </code></pre> <p>That doesn't look right, and it isn't. However, if I reformat your block comment to something that Vim recognizes (this is how I write my block comments anyways), like so:</p> <pre><code>/* * Line 1 of some large comment block, * hopefully it contains well written documentation. I'd * now like 'hopefully' to be on the first line. */ </code></pre> <p>and then I <code>gq%</code> (with <code>textwidth</code> still 50) I get:</p> <pre><code>/* * Line 1 of some large comment block, hopefully * it contains well written documentation. I'd now * like 'hopefully' to be on the first line. */ </code></pre> <p>That seems like it worked. The word "now" was moved from the third line to the second, too, but I'd argue that that was a good decision on Vim's part. One more note: if you don't like those leading <code>*</code>s, Vim will also do a good job with this format:</p> <pre><code>/* Line 1 of some large comment block, hopefully it contains well written documentation. I'd now like 'hopefully' to be on the first line. */ </code></pre> <p>When I <code>gq%</code> this, I get:</p> <pre><code>/* Line 1 of some large comment block, hopefully it contains well written documentation. I'd now like 'hopefully' to be on the first line. */ </code></pre> <p>A little funny, but it makes sense. Looks more like a paragraph to me. Hopefully something in here is useful.</p> <p><strong>Edit:</strong></p> <p>As progo handily mentioned in another answer, you can use <code>gqap</code> everywhere I've used <code>gq%</code> above. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload