VIM - combine a string of several files into one file

I am trying to go through a list of buffers, select one line from each buffer and merge them into one file (or another buffer). How in:

file1

... line2 ...

file2

... line2 ...

file3

... line2 ...

etc.

all in:

Myfile

line2 (file1)

line2 (file2)

line2 (file3)

I cannot get my registers to work, and bufdo causes me heartache for some reason ...

[clarification] I was hoping I could use bufdo to go through all my buffers, rip out the second line from each and add it to the register.

Then, in another file, just paste the contents of the register into it (containing the second line of all my buffers).

+4
source share
1 answer

You should do this with something like:

bufdo normal 2G"Ayy 

which iterates through buffers and runs this command in normal mode. 2G goes to the corresponding line, and "Ay Ayanks to register a, adding instead of overwriting (since A is capitalized). Before starting, make sure that register a is empty!

You can use windo or tabdo if you have windows or tabs instead of buffers.

+4
source

Source: https://habr.com/ru/post/1389336/


All Articles