How to insert a column of text after another column of text in Vim?

I have two columns with text, and I want them to be side by side. For example, I have

abc def ghi 

and

 123 456 789 

I want too

 123 abc 456 def 789 ghi 

All I can find is to insert the same row at the end of each row in the column. I cannot figure out how to insert a multi-line block of text at the end of another column.

+55
vim
Feb 02 2018-12-12T00:
source share
6 answers

Use the visual block ( ctrl-v ) to cut out the column of letters. Then go to the first row of the number column. Move to the end and make one space. Then insert a column of letters.

+45
Feb 02 2018-12-12T00:
source share

I was wondering why “visual block mode” does not work for me. The key is yank (or delete) in visual mode.

I need to copy some things from excel columns with variable length. Here is how I do it:

 Names Donald Knuth Sebastian Thrun Peter Norvig Satoshi Nakamoto Age 100 50 60 45 

Let's say you want to put the second column after the first.

  • Remove it in visual mode:
    • Move the cursor to the beginning of Age
    • Press Ctrl + v to enter visual mode.
    • Move the cursor 5 to 45
    • Press y to remove (or d to remove)

You are now twitching in visual mode.

  1. Paste (in normal mode)

    • Go to the end of the first line and add more spaces because it is shorter than the second line, for example. If you insert a “block” without adding extra spaces, it overwrites “run” in Sebastian Thrun.

    • Now you are on the first line, insert some spaces after the last character. Make sure you are not in insert mode and press p to insert the block. (If you want to paste in insert mode, use ctrl+r " )

enter image description here

+55
Dec 18 '14 at 9:12
source share

You have:

 abc def ghi 123 456 789 

Move the cursor to a . Then CTRL+V and move the cursor to i . Press y .

Then add a space after character 3 and press p .

Done.

+15
Feb 02 2018-12-12T00:
source share

This may seem obvious, but if you paste from an external copied buffer, it will not work with pasting only visual mode. What you can do is first make a plain paste in the empty area and vertically cut / paste using the above method.

+3
Nov 05 '15 at 1:16
source share

If you want to manually set the register type, say block, use this

 :call setreg(0, getreg(0), 'b') 

or

 :call setreg('*', getreg('*'), 'b') 

Useful for inserting a column from a spreadsheet editor.

See :help setreg and vimtip for details.

0
Feb 08 '18 at 5:18
source share

If you are on a Mac and cannot understand why the insert inserts the block into new lines, this is because you are using a system board.

No problem, just paste / paste with buffers:

  1. Ctrl v - select what you want to pull
  2. " letter y - jerk to the letter buffer
  3. Go where you want to paste
  4. " letter p - insert from letter buffer

Make sure letter not + as it is a buffer of the system buffer and, therefore, it will have the same effect.

0
Jan 21 '19 at 20:19
source share



All Articles