Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The solution is centered on the <code>:g</code> command. From the help:</p> <pre><code> :g :global E147 E148 :[range]g[lobal]/{pattern}/[cmd] Execute the Ex command [cmd] (default ":p") on the lines within [range] where {pattern} matches. </code></pre> <p>So basically, the solution executes some ex commands on lines that have a "V", which are exactly the ones that need editing. You probably noticed that earlier solutions rely on duplicating the lines, rather than really changing them. This solution specially shows an interesting pattern:</p> <pre><code>3jYjVp3jYjVp3jYjVpZZ ^ ^ ^ </code></pre> <p>Which could be reduced with a macro:</p> <pre><code>qa3jYjVpq3@aZZ </code></pre> <p>The solution using the <code>:g</code> command does basically the same thing. The first command executed is <code>t.</code>. From the help:</p> <pre><code> :t :t Synonym for copy. :[range]co[py] {address} :co :copy Copy the lines given by [range] to below the line given by {address}. </code></pre> <p>The address given was <code>.</code>, which means current line:</p> <pre><code>Line numbers may be specified with: :range E14 {address} {number} an absolute line number . the current line :. $ the last line in the file :$ % equal to 1,$ (the entire file) :% 't position of mark t (lowercase) :' 'T position of mark T (uppercase); when the mark is in another file it cannot be used in a range /{pattern}[/] the next line where {pattern} matches :/ ?{pattern}[?] the previous line where {pattern} matches :? \/ the next line where the previously used search pattern matches \? the previous line where the previously used search pattern matches \&amp; the next line where the previously used substitute pattern matches </code></pre> <p>So the ex command <code>t.</code> means "copy current line to below the current line". Then, there is a bar which:</p> <pre><code> :bar :\bar '|' can be used to separate commands, so you can give multiple commands in one line. If you want to use '|' in an argument, precede it with '\'. </code></pre> <p>And the <code>d</code> command, which obviously deletes the line. It was given a range of <code>+</code>, meaning the "current line + 1". You could pass <code>.+1</code> but <code>+</code> for short. These info can be read surrounding the help for <code>:range</code>:</p> <pre><code>The default line specifier for most commands is the cursor position, but the commands ":write" and ":global" have the whole file (1,$) as default. Each may be followed (several times) by '+' or '-' and an optional number. This number is added or subtracted from the preceding line number. If the number is omitted, 1 is used. </code></pre> <p>And that's it.</p> <pre><code>:g/V/t.|+d&lt;CR&gt;ZZ </code></pre> <blockquote> <p>On every line that has a "V", copy it down and delete the next line. Write and quit.</p> </blockquote> <hr> <p>One thing that I didn't mention is why the <code>:g</code> commands are executed three times instead of 6 or even more (lines are duplicated along the process). The <code>:g</code> command starts positioning the cursor on line one, and goes down to $. But if the commands change the current line, <code>:g</code> continues from there. So:</p> <pre><code>:g/V/ </code></pre> <p>Current line is 4. Now:</p> <pre><code>t. </code></pre> <p>This moves the cursor to line 5. And then:</p> <pre><code>+d </code></pre> <p>Deletes line 6, the cursor remain in 5. So the next <code>:g</code> match will be in line 8.</p>
    singulars
    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