Add a block of text to end of lines

2018-04-30 22:12:45

Not sure if this one is possible, but say I have a file with two blocks of text, in this case English words and their French translations. eg:

vivre

aimer

étudier

to live

to like

to study

Now I want to copy the second block and match them by position only, perhaps with a '-', eg:

vivre - to live

aimer - to like

étudier - to study

Sure. A macro can do this without too much trouble. With your cursor on the first character of the first line (Anything in <> is a special key and not a litteral ):

qq"ay$:let @a .= ' - '4j"Ay$jjoa^6kq

qq: Starts a macro in register q.

"ay$: Yank to the end of line into the a register. (Not yy to avoid the newline)

:let @a .= ' - ': Append the text - to register a.

4j"Ay$: Go down to the corresponding english text and append to regester a with A.

2joa: Print the contents of register a.

^6k: Put the cursor back to the beginning to yank the next term.

q: End the macro

Then execute the macro w

  • Sure. A macro can do this without too much trouble. With your cursor on the first character of the first line (Anything in <> is a special key and not a litteral ):

    qq"ay$:let @a .= ' - '4j"Ay$jjoa^6kq

    qq: Starts a macro in register q.

    "ay$: Yank to the end of line into the a register. (Not yy to avoid the newline)

    :let @a .= ' - ': Append the text - to register a.

    4j"Ay$: Go down to the corresponding english text and append to regester a with A.

    2joa: Print the contents of register a.

    ^6k: Put the cursor back to the beginning to yank the next term.

    q: End the macro

    Then execute the macro with #@q where # is how many times you want to execute the macro (A.K.A. how many lines you have to copy). Any numbers in the macro may have to be adjusted for how many lines you need to skip over in your real text.

    2018-05-01 00:42:51