a line of php repeated 8 times

Emacs: yank a line multiple times from the kill ring

Today I needed to copy a line multiple times in emacs. I needed 8 copies, but how to do that in emacs short of pressing C-y to yank 8 times? My initial guess was to try C-u 8 C-y but that yanks the 8th item from the kill ring.
Fuco on #emacs supplied the awesome answer:
F3 C-y C-8 F4
So what does that do? F3starts recording a macro, C-yyanks the line, then within the macro itself you can add a numeric argument of 8 using C-8. End recording of the macro with F4. Emacs then runs the macro 8 times. Recall that pressing F4 after ending recording of the macro runs the macro.


Comments

2 responses to “Emacs: yank a line multiple times from the kill ring”

  1. The F keys don’t work well for me, so here is how to do this without using Function keys:
    another way to do this:
    C-x ( — start keyboard macro
    C-y — yank from kill ring
    C-x ) — end kbd macro
    Then you can reuse this as much as you like.
    C-x e — execute the macro
    C-u 10 C-x e — execute the macro 10 times

Leave a Reply

Your email address will not be published. Required fields are marked *