5

I've enabled the relativenumbers in Vim. I would like to automate the following operation.

ma(number)(j|k)yy`a(p|P)

that is to say:

  • mark the curr position in 'a'
  • move up or down by 'number' lines
  • yank current line
  • jump back to position 'a'
  • put line up or down

I'm looking for an easier way to perform the same. Is there one?

Thanks.

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
nico
  • 101
  • 3

1 Answers1

5

I guess I found the right way to do it with

:.(+|-)(number)y

for example

:.-3y

yanks 3 lines above.

nico
  • 101
  • 3
  • 2
    If you want to duplicate a line, you could also use the :t command. To copy the 5th line above you under the current one, you would type: :-5t. To copy the 10th line under you above the current one, you would type: :+10t-1 The number before the :t command gives the position of the line you want to copy relative to the current one, while the number after it gives the position of the line under which you want to paste. – saginaw Feb 27 '16 at 17:36