20

Assume I have

1 - funct1
2- funct 2
3 - funct 3 
4 line 4

how can I copy line 1 and 3 (not a range of lines) and paste them, for example at line 8? If I do this in way with | arg like ( 1y|3y), I would yank lines to several registers, right? But how can I put from several registers at once?

33

You can append to a register instead of erasing it by using the upper-case letter instead of the lower-case one.

For example:

:1y a      # copy line 1 into register a (erases it beforehand)
:3y A      # copy line 3 into register a (after its current content)
8G  # go to line 8
"ap        # print register a
  • 1
    You can also do this in normal mode with "ayyjj"Ayy"ap. – wchargin Apr 28 '16 at 15:35
  • 5
    (or 1G"ayy3G"Ayy8G"ap for explicit line numbers) – wchargin Apr 28 '16 at 15:36
  • 1
    Isn't it just G for go to line, not <C-G>? – David Apr 28 '16 at 16:38
  • 1
    This is so cool. You can keep adding as many things to buffer A as you want and it'll keep it all. To start over, put something in register a – CornSmith Apr 28 '16 at 16:58
  • 1
    @CornSmith Nitpick: buffer is a very specific term in the context of vim. "a is a register. – Doorknob Apr 29 '16 at 12:34
1

You can use the :copy command, which can be abbreviated as :t:

:1t8
:3t8

If you want to copy a range of lines (e.g. all lines from 1 to 3) you can do it like this:

:1,3t8
  • I want to copy lines by number, but not a RANGE OF LINES... Can i with something like t command append to line? – Whats Myname Apr 28 '16 at 13:25
0
1Gyy7Gp #use 7 if you wish to paste the line at 8
3Gyy8Gp #use 8 if you wish to paste the line at 9
  • These can be better expressed with the :t command, which also doesn't clear the " or 0 registers. – Doorknob Apr 29 '16 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.