Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I would like to paste a column of text at the end of irregular-length lines.

For example, I would like to paste the following:

SRR447882.fastq.gz SRR447883.fastq.gz SRR447944.fastq.gz 

at the end of these lines:

TIL01_ TIL01_ TIL04-TIP285_ 

Many times in the past, I simply create enough space on the first line that pasting will not come before the end of the existing text in the longest line. But then I need to go back and remove whitespace.

I have tried googling "vim column paste irregular length rows" and similar queries.

like image 831
Christopher Bottoms Avatar asked Nov 18 '13 14:11

Christopher Bottoms


People also ask

How do I paste at the end of a line in Vim?

Therefore, the key sequence would from command mode, A to get into insert mode at end of line, <space> to insert a space, then Ctrl-v to paste. Alternatively, while in insert mode, use the mouse to put the cursor at the end of a line, <space> then Ctrl-v .

How do I paste a column in vim?

Press Esc, and you'll see you have inserted a column of single spaces. Now use ctrl+v again to highlight the column of spaces. Use p to paste your original column selection.

How do I paste a block of text in Vim?

Pasting over a block of text You can copy a block of text by pressing Ctrl-v (or Ctrl-q if you use Ctrl-v for paste), then moving the cursor to select, and pressing y to yank. Now you can move elsewhere and press p to paste the text after the cursor (or P to paste before).


2 Answers

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

like image 150
Kent Avatar answered Oct 27 '22 00:10

Kent


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.

like image 23
Zoneur Avatar answered Oct 27 '22 00:10

Zoneur