# concat file content horizontally in vi/vim

I have a text file that contains a big matrix, that columns are split like the following example:

``````     col1 col2 col3
row1  ..   ..   ..
row2  ..   ..   ..
row3  ..   ..   ..
row4  ..   ..   ..
row5  ..   ..   ..
row6  ..   ..   ..

col4 col5 col6
row1  ..   ..   ..
row2  ..   ..   ..
row3  ..   ..   ..
row4  ..   ..   ..
row5  ..   ..   ..
row6  ..   ..   ..
``````

How can I concatenate the splitted columns horizontally so that the file can be something like this:

``````     col1 col2 col3 col4 col5 col6
row1  ..   ..   ..   ..   ..   ..
row2  ..   ..   ..   ..   ..   ..
row3  ..   ..   ..   ..   ..   ..
row4  ..   ..   ..   ..   ..   ..
row5  ..   ..   ..   ..   ..   ..
row6  ..   ..   ..   ..   ..   ..
``````
-
Was "row1 .. row6" and "col1 .. col6" part of file or just imaginary ? –  warl0ck Oct 7 '12 at 5:41
Just as an example,so it is imaginary. The actual size is much larger. –  xiaohan2012 Oct 7 '12 at 6:17
Why do you need to use `vi`? It would be easier with `tail`/`head` and `paste`. –  mouviciel Oct 7 '12 at 7:15

What you want is the “Visual mode blockwise”, see `:h ctrl-v`. Here the steps to reproduce:

• move the cursor to the column before `col4`
• press Ctrl + V
• go all the way down: G
• mark to the end of the columns: \$
• delete the columns: d
• go to the end of `col3`: g g \$
• paste the columns: p
-
Thanks, it works! –  xiaohan2012 Oct 8 '12 at 4:23
``````paste FILE1.txt FILE2.txt
``````

I need to know if row1, row2 etcc are values or just to orient? if they are value it should be like:

``````cut -b 5- FILE2.txt | paste FILE1.txt -
``````
-