I wanted to copy a series of lines to a specific place in a file, and these are the options I see, all with g, the first two from the power of g

  1. clear register, copy matching lines to register, paste from register
  2. copy to end of file, jump to end of file, yank lines, jump back and paste
  3. :g/pattern/t80 paste to the specific line I'm at, reverse order of lines with !tac

All of them are actually a bit convoluted, I think probably 1 is the fastest, as you don't have to check the line number where you want to paste. Is there another way, where I place my cursor to where I want the lines pasted and they get pasted in order?

  • What about :g/pattern/t.? . refers to the current line. There is also -, which refers to the line above.
    – husB
    Aug 10, 2022 at 8:02
  • 2
    @husB that would duplicate the lines; during :global, . is the line on which the command argument to :global is running.
    – D. Ben Knoble
    Aug 10, 2022 at 13:27

1 Answer 1


Use a mark

The problem with line numbers is that they always stay in the same place, resulting in the reversed ordering you see in your option 3. Marks, on the other hand, can move with the content.

Specifically, (as Matt points out in a comment) you can use the automatic '' mark, which Vim helpfully sets before executing your :global command.

  • 1
    This could be improved: :g/PATTERN/t''-
    – Matt
    Aug 10, 2022 at 9:55
  • @Matt thanks! I’ll edit
    – Rich
    Aug 10, 2022 at 9:56
  • nice! really nice!
    – fbence
    Aug 10, 2022 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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