4
2
I have 2 files
file1.txt
a =
b =
file2.txt
1
2
Can I merge them using gvim so that the output looks like :
a = 1
b = 2
4
2
I have 2 files
file1.txt
a =
b =
file2.txt
1
2
Can I merge them using gvim so that the output looks like :
a = 1
b = 2
7
Yank a vertical block: Select e.g. the lines in file2.txt
with CTRLv, yank with y and paste after moving to end of the first line in file1.txt
with p.
If you run vim
on a GNU stack you could also use the paste
program to do the same. Use -d
to specify what delimiter to use between the fields from the files.
paste -d "" 1 2 > merged.txt
1
works with pure vim as well:
% vim -O file1.txt file2.txt # open both files vertically splitted
then in file1.txt yank the block to a named register, lets say 'a':
then switch over to file2.txt and do a:
0
Also could you on Linux use the command :read for paste text of one file to other file, for example:
Both case, first open a file with vim, after you positions in a section of the file and execute:
:read file1.txt
or
: read! cat file1.txt
It´s very useful for join content of two or more files...
This doesn't answer the question. Your answer is about cut/paste, while the question is very clearly about merging. Please read the questions carefully and avoid posting unrelated information. – music2myear – 2017-01-26T23:18:56.283
0
if you're working on Unix or Linux, just use the paste command:
:%!paste - file2.txt
this also works in the classic vi, or direct from the command line:
$ paste file1.txt file2.txt >out.txt
Hope, this helps
There is a similar question (2 blocks from the same file) on SO: Merge multiple lines (two blocks) in Vim
– ThiefMaster – 2012-06-05T06:42:16.320