In vim, how do I paste a column of text to the end of irregular length lines?

You can do it like this:

  • Start on the first line of the second block
  • qq, start recording the q macro
  • 4k, go up four lines
  • d$, delete till the end of line
  • 4j, go back to the previous line
  • $p, paste the line at the end of the line
  • q, stop recording the macro
  • jVG, go down one line and select the remaining lines
  • :norm! @q, apply the macro to the selection

It does however leave space where the previous text was. @Kent one's is still easier.


My UnconditionalPaste plugin has (among others) gBp / gBP mappings that paste register contents as a minimal fitting (not rectangular) block with a jagged right edge.

demo

enter image description here


You could try to do the following four steps:

  1. block-wise select the first 3 lines (you want to paste later), and press y
  2. line-wise select (V) the 3 lines ending with _, press :right
  3. then move cursor to the end of the first line($), paste the yanked text
  4. gv re-select the lines, press :left

It looks like this:

enter image description here


Step 1 - goto to the start of the SPP... lines, then start Visual mode linewise with V (capital V), press j two times to get the desired lines selected then press y.

Step 2 - goto the start of the TIL0... lines, then start Visual mode linewise with V (capital V), press j two times to get the desired lines selected then type...

:s;$;\=' ' . split(@")[line('.')-line("'<")];g`

and press Enter.

Tags:

Vim